Notes about the semantic analyzer
Mypy 0.710 introduced a new semantic analyzer, and the old semanticanalyzer was removed in mypy 0.730. Support for the new semantic analyzerrequired some changes to existing plugins. Here is a short summary of themost important changes:
- The order of processing AST nodes is different. Code outsidefunctions is processed first, and functions and methods areprocessed afterwards.
- Each AST node can be processed multiple times to resolve forwardreferences. The same plugin hook may be called multiple times, sothey need to be idempotent.
- The
anal_type()
API method returnsNone
if some part ofthe type is not available yet due to forward references, for example. - When looking up symbols, you may encounter placeholder nodes thatare used for names that haven’t been fully processed yet. You’llgenerally want to request another semantic analysis iteration bydeferring in that case.
See the docstring at the top ofmypy/plugin.pyfor more details.