py-good icon indicating copy to clipboard operation
py-good copied to clipboard

Using .extend() from voluptuous with good Schema

Open typon opened this issue 9 years ago • 3 comments

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']

typon avatar May 20 '16 14:05 typon

How does this work when you try to extend a schema that uses a list as a base?

Varriount avatar Jun 01 '17 16:06 Varriount

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.

kolypto avatar Dec 28 '18 13:12 kolypto

I'll consider implementing this in the coming release

kolypto avatar Dec 28 '18 13:12 kolypto