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

Map containing only Optionals does not validate an empty dict #195

Open
snorthman opened this issue Apr 4, 2023 · 1 comment
Open

Map containing only Optionals does not validate an empty dict #195

snorthman opened this issue Apr 4, 2023 · 1 comment

Comments

@snorthman
Copy link

from strictyaml import load, Str, Map, Optional

schema = Map({
 Optional("a", "default_value_a"): Str(),
 Optional("b", "default_value_b"): Str(),
 Optional("c", "default_value_c"): Str()
})

print(load('', schema))

Expectation:

YAML({'a': 'default_value_a', 'b': 'default_value_b', 'c': 'default_value_c'})

Reality:

YAMLValidationError: when expecting a mapping found a blank string

Argument:

I want to use the optional values as defaults, such that if you input '' you get a YAML will all defaults set. However, this is currently not possible because essentially Map({}) is impossible to validate in strictyaml.

One would expect Map({}) to be equal to EmptyDict(), but a: fails to validate for Map({}) but succeeds for EmptyDict().

My "default" design is not possible in strictyaml, and this is due to Map({}) not validating empty dicts.

Proposal:

Allow Map({}) to validate empty dicts.

@CarrotManMatt
Copy link

I believe this has been answered here: #203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants