-
Notifications
You must be signed in to change notification settings - Fork 2
Support validation of arbitrary dictionaries. #14
Copy link
Copy link
Open
Labels
Description
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"]Reactions are currently unavailable