Skip to content

Support validation of arbitrary dictionaries. #14

@itsjohncs

Description

@itsjohncs

Currently, attribute names are restricted to valid Python identifiers. I have a need to perform validation on arbitrary dictionaries which contain configuration data for Galah. Therefore I propose adding support for the following syntax.

class FooConfiguration(DictModel):
    # Keys can be any valid valid key for a Python dictionary
    _fields = {
        u"arbitrary/key": StringField(),
        "another!?key??": IntegralField()
    }

# No need to bother with a seperate from_dict() function in this case, we will
# always be validating dictinaries after all.
config = FooConfiguration({
    u"arbitrary/key": "hello!",
    "another!?key??": 3
})

# Validation stays almost exactly the same (I imagine the inherited function
# can actually be left alone).
config.validate()

# Accessing values is now done through __getitem__()
print config[u"arbitrary/key"]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions