Skip to content

Instantly share code, notes, and snippets.

@erickpeirson
Last active April 26, 2019 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erickpeirson/b781bc1ce3418cfcfcfebdf689203ddf to your computer and use it in GitHub Desktop.
Save erickpeirson/b781bc1ce3418cfcfcfebdf689203ddf to your computer and use it in GitHub Desktop.
class JSONSchemaPlugin(Plugin):
"""Provides support for the JSON Schema as TypedDict."""
# I put the placeholder class in a package called `jsonschema_typed`.
JSONSchema = 'jsonschema_typed.types.JSONSchema'
def get_type_analyze_hook(self, fullname: str) -> Optional[Callable]:
"""Produce an analyzer callback if a JSONSchema annotation is found."""
if fullname == self.JSONSchema:
def callback(ctx: AnalyzeTypeContext) -> TypedDictType:
"""Generate annotations from a JSON Schema."""
... # Here is where we need to generate the TypedDictType.
return callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment