py-good
py-good copied to clipboard
Using .extend() from voluptuous with good Schema
Is it possible to extend schema like in voluptuous? I really miss this feature.
from voluptuous import Schema person = Schema({'name': str}) person_with_age = person.extend({'age': int}) sorted(list(person_with_age.schema.keys())) ['age', 'name']
How does this work when you try to extend a schema that uses a list as a base?
Not currently, no: you can only do this manually:
person_schema = {'name': str}
age_schema = {'age': int}
person = Schema(person_schema)
person_with_age = Schema({ **person_schema, **age_schema }) # merged dicts (Python 3.5+)
Same thing with a list: manually update a list.
I'll consider implementing this in the coming release