Skip to content

Commit

Permalink
Update extending_mypy.rst (#10222)
Browse files Browse the repository at this point in the history
Two things I have changed:
1. `get_function_signature_hook` was missing from docs, but it is defined https://github.com/python/mypy/blob/ac66403cb4374b858786350b96e7f5972db84bcd/mypy/plugin.py#L368-L376
2. While reading the docs, this `UserDefined` for `get_class_decorator_hook` example caught my eye. It was not clear how `UserDefined` and `@customize` work. I believe that `@dataclass` example is better for two reasons. First, it is an existing API and is already familiar to our users. Secondly, there's an actual plugin for it, so people can see how it is implemented
  • Loading branch information
sobolevn authored Apr 11, 2021
1 parent b31122f commit 6fc5f38
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/source/extending_mypy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ For example:
...
yield timer()
**get_function_signature_hook** is used to adjust the signature of a function.

**get_method_hook()** is the same as ``get_function_hook()`` but for methods
instead of module level functions.

Expand Down Expand Up @@ -202,14 +204,13 @@ to match runtime behaviour:

.. code-block:: python
from lib import customize
from dataclasses import dataclass
@customize
class UserDefined:
pass
@dataclass # built-in plugin adds `__init__` method here
class User:
name: str
var = UserDefined
var.customized # mypy can understand this using a plugin
user = User(name='example') # mypy can understand this using a plugin
**get_metaclass_hook()** is similar to above, but for metaclasses.

Expand Down

0 comments on commit 6fc5f38

Please sign in to comment.