Skip to content

Instantly share code, notes, and snippets.

@erickpeirson
Last active April 26, 2019 12:43
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/7f38aa69055918972c45a70f9484281c to your computer and use it in GitHub Desktop.
Save erickpeirson/7f38aa69055918972c45a70f9484281c to your computer and use it in GitHub Desktop.
class ThePlugin:
"""My custom plugin for mypy."""
def get_type_analyze_hook(self, fullname: str) -> Optional[Callable[[AnalyzeTypeContext], Type]]:
"""Customize analysis of specific types."""
if fullname == 'somemodule.SomeName':
return analyze_some_name
return None # mypy will just move on without us.
def analyze_some_name(ctx: AnalyzeTypeContext) -> Type:
"""The name 'somemodule.SomeName' just refers to str."""
return ctx.api.named_type('builtins.str')
def plugin(version: str) -> Type[JSONSchemaPlugin]:
"""See `https://mypy.readthedocs.io/en/latest/extending_mypy.html`_."""
return JSONSchemaPlugin
[mypy]
plugins = myPlugin.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment