High-level overview

Every entry point function should accept a single string argumentthat is a full mypy version and return a subclass of mypy.plugin.Plugin:

  1. from mypy.plugin import Plugin
  2.  
  3. class CustomPlugin(Plugin):
  4. def get_type_analyze_hook(self, fullname: str):
  5. # see explanation below
  6. ...
  7.  
  8. def plugin(version: str):
  9. # ignore version argument if the plugin works with all mypy versions.
  10. return CustomPlugin

During different phases of analyzing the code (first in semantic analysis,and then in type checking) mypy calls plugin methods such asget_type_analyze_hook() on user plugins. This particular method, for example,can return a callback that mypy will use to analyze unbound types with the givenfull name. See the full plugin hook method list below.

Mypy maintains a list of plugins it gets from the config file plus the default(built-in) plugin that is always enabled. Mypy calls a method once for eachplugin in the list until one of the methods returns a non-None value.This callback will be then used to customize the corresponding aspect ofanalyzing/checking the current abstract syntax tree node.

The callback returned by the get_xxx method will be given a detailedcurrent context and an API to create new nodes, new types, emit error messages,etc., and the result will be used for further processing.

Plugin developers should ensure that their plugins work well in incremental anddaemon modes. In particular, plugins should not hold global state due to cachingof plugin hook results.