Skip to content

Commit 488ad4f

Browse files
authored
Bundle misc/proper_plugin.py as a part of mypy (#16036)
I modified ```diff diff --git mypy/binder.py mypy/binder.py index 8a68f24..194883f86 100644 --- mypy/binder.py +++ mypy/binder.py @@ -345,7 +345,7 @@ class ConditionalTypeBinder: self._cleanse_key(dep) def most_recent_enclosing_type(self, expr: BindableExpression, type: Type) -> Type | None: - type = get_proper_type(type) + # type = get_proper_type(type) if isinstance(type, AnyType): return get_declaration(expr) key = literal_hash(expr) ``` to see if it still works. It is: ```python » python runtests.py self run self: ['/Users/sobolev/Desktop/mypy/.venv/bin/python', '-m', 'mypy', '--config-file', 'mypy_self_check.ini', '-p', 'mypy', '-p', 'mypyc'] mypy/binder.py:349: error: Never apply isinstance() to unexpanded types; use mypy.types.get_proper_type() first [misc] if isinstance(type, AnyType): ^~~~~~~~~~~~~~~~~~~~~~~~~ mypy/binder.py:349: note: If you pass on the original type after the check, always use its unexpanded version Found 1 error in 1 file (checked 288 source files) FAILED: self ``` I will add this plugin to my CI checks in like ~5 plugins I maintain :) - https://github.com/typeddjango/django-stubs - https://github.com/typeddjango/djangorestframework-stubs - https://github.com/dry-python/returns - https://github.com/dry-python/classes - https://github.com/wemake-services/mypy-extras Closes #16035
1 parent 92e054b commit 488ad4f

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ include build-requirements.txt
3434
include test-requirements.txt
3535
include mypy_self_check.ini
3636
prune misc
37-
include misc/proper_plugin.py
3837
graft test-data
3938
include conftest.py
4039
include runtests.py

docs/source/extending_mypy.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,12 @@ mypy's cache for that module so that it can be rechecked. This hook
237237
should be used to report to mypy any relevant configuration data,
238238
so that mypy knows to recheck the module if the configuration changes.
239239
The hooks should return data encodable as JSON.
240+
241+
Useful tools
242+
************
243+
244+
Mypy ships ``mypy.plugins.proper_plugin`` plugin which can be useful
245+
for plugin authors, since it finds missing ``get_proper_type()`` calls,
246+
which is a pretty common mistake.
247+
248+
It is recommended to enable it is a part of your plugin's CI.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
This plugin is helpful for mypy development itself.
3+
By default, it is not enabled for mypy users.
4+
5+
It also can be used by plugin developers as a part of their CI checks.
6+
7+
It finds missing ``get_proper_type()`` call, which can lead to multiple errors.
8+
"""
9+
110
from __future__ import annotations
211

312
from typing import Callable

mypy_self_check.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ disallow_any_unimported = True
55
show_traceback = True
66
pretty = True
77
always_false = MYPYC
8-
plugins = misc/proper_plugin.py
8+
plugins = mypy.plugins.proper_plugin
99
python_version = 3.8
1010
exclude = mypy/typeshed/|mypyc/test-data/|mypyc/lib-rt/
1111
new_type_inference = True

0 commit comments

Comments
 (0)