Skip to content

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

Open
@snorthman

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions