keleshev / schema

Schema validation just got Pythonic
MIT License
2.88k stars 215 forks source link

Generate a TypedDict subclass #259

Open AckslD opened 3 years ago

AckslD commented 3 years ago

I'm just starting to use schema and was wondering if, given a schema, it is possible to generate a subclass of TypedDict to be used in type annotations?

For example if I would have

schema = Schema({'foo': [str], 'bar': {int, float}})

can I get the equivalent of

from typing import TypingDict

class SchemaType(TypingDict):
    foo: List[str]
    bar: Set[Union[int, float]]

without having to effectively write out the schema again?