@@ -155,23 +155,9 @@ When analyzing this code, mypy will call ``get_type_analyze_hook("lib.Vector")``
155
155
so the plugin can return some valid type for each variable.
156
156
157
157
**get_function_hook() ** is used to adjust the return type of a function call.
158
- This is a good choice if the return type of some function depends on *values *
159
- of some arguments that can't be expressed using literal types (for example
160
- a function may return an ``int `` for positive arguments and a ``float `` for
161
- negative arguments). This hook will be also called for instantiation of classes.
162
- For example:
163
-
164
- .. code-block :: python
165
-
166
- from contextlib import contextmanager
167
- from typing import TypeVar, Callable
168
-
169
- T = TypeVar(' T' )
170
-
171
- @contextmanager # built-in plugin can infer a precise type here
172
- def stopwatch (timer : Callable[[], T]) -> Iterator[T]:
173
- ...
174
- yield timer()
158
+ This hook will be also called for instantiation of classes.
159
+ This is a good choice if the return type is too complex
160
+ to be expressed by regular python typing.
175
161
176
162
**get_function_signature_hook ** is used to adjust the signature of a function.
177
163
@@ -251,31 +237,3 @@ mypy's cache for that module so that it can be rechecked. This hook
251
237
should be used to report to mypy any relevant configuration data,
252
238
so that mypy knows to recheck the module if the configuration changes.
253
239
The hooks should return data encodable as JSON.
254
-
255
- Notes about the semantic analyzer
256
- *********************************
257
-
258
- Mypy 0.710 introduced a new semantic analyzer, and the old semantic
259
- analyzer was removed in mypy 0.730. Support for the new semantic analyzer
260
- required some changes to existing plugins. Here is a short summary of the
261
- most important changes:
262
-
263
- * The order of processing AST nodes is different. Code outside
264
- functions is processed first, and functions and methods are
265
- processed afterwards.
266
-
267
- * Each AST node can be processed multiple times to resolve forward
268
- references. The same plugin hook may be called multiple times, so
269
- they need to be idempotent.
270
-
271
- * The ``anal_type() `` API method returns ``None `` if some part of
272
- the type is not available yet due to forward references, for example.
273
-
274
- * When looking up symbols, you may encounter *placeholder nodes * that
275
- are used for names that haven't been fully processed yet. You'll
276
- generally want to request another semantic analysis iteration by
277
- *deferring * in that case.
278
-
279
- See the docstring at the top of
280
- `mypy/plugin.py <https://github.com/python/mypy/blob/master/mypy/plugin.py >`_
281
- for more details.
0 commit comments