Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting a scheme #272

Open
muuvmuuv opened this issue Dec 11, 2019 · 1 comment
Open

Support setting a scheme #272

muuvmuuv opened this issue Dec 11, 2019 · 1 comment
Labels
type: feature A self-contained enhancement or new feature

Comments

@muuvmuuv
Copy link

Would be great if I could set a scheme for load(s) so if someone passes the one type it will throw an type error.

I expect something like:

import toml

from pathlib import Path


toml_data = """
[options]
enabled="true"
input="tests/struct2"
digit=12.5
"""

toml_scheme = {
    "options": {
        "enabled": {
            "type": bool,
            "default": True
        },
        "input": {
            "type": Path,
            "default": Path.cwd()
        },
        "digit": {
            "type": float,
            "default": 0.2,
            "validator": (lambda n: type(n) is float),
            "parser": (lambda n: n % 2)
        }
    }
}


def get_config(config_path):
    try:
      parsed_toml = toml.loads(toml_data, scheme=toml_scheme)
    except toml.TomlSchemeError as e:
      raise toml.TomlSchemeException(e)
    print(parsed_toml)
    return parsed_toml
@chrizzFTD
Copy link

Wondering if any of your needs would be solved by the proposed schema validator specification at toml-lang/toml#116
It's meant to be something to solve post-1.0, though

@pradyunsg pradyunsg added the type: feature A self-contained enhancement or new feature label Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A self-contained enhancement or new feature
Projects
None yet
Development

No branches or pull requests

3 participants