mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-14 15:57:08 +08:00
[WIP/RFC] Revisit patching of mypy builtins (reveal_{type,locals}) (#615)
* Revisit patching of mypy builtins (reveal_{type,locals})
Fixes https://github.com/typeddjango/django-stubs/issues/609
Reverts ee58b18f15
* Create test_patching.yml
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
@@ -29,9 +29,6 @@ def make_generic_classes(
|
||||
with suppress(AttributeError):
|
||||
delattr(el.cls, "__class_getitem__")
|
||||
|
||||
del builtins.reveal_type
|
||||
del builtins.reveal_locals
|
||||
|
||||
def factory(django_version: Optional[_VersionSpec] = None) -> None:
|
||||
if django_version is not None:
|
||||
monkeypatch.setattr(patch, "VERSION", django_version)
|
||||
@@ -71,11 +68,15 @@ def test_patched_version_specific(
|
||||
assert el.cls[int] is el.cls
|
||||
|
||||
|
||||
def test_patched_mypy_builtins(
|
||||
def test_mypy_builtins_not_patched_globally(
|
||||
make_generic_classes: _MakeGenericClasses,
|
||||
) -> None:
|
||||
"""Ensures that we properly patch builtins with `mypy` specific helpers."""
|
||||
"""Ensures that builtins are not patched with `mypy` specific helpers.
|
||||
|
||||
This should only happend during `django.setup()`
|
||||
(https://github.com/typeddjango/django-stubs/issues/609).
|
||||
"""
|
||||
make_generic_classes()
|
||||
|
||||
assert builtins.reveal_type
|
||||
assert builtins.reveal_locals
|
||||
assert not hasattr(builtins, "reveal_type")
|
||||
assert not hasattr(builtins, "reveal_locals")
|
||||
|
||||
15
django_stubs_ext/tests/typecheck/test_patching.yml
Normal file
15
django_stubs_ext/tests/typecheck/test_patching.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
- case: patch_reveal_type_during_django_setup
|
||||
main: |
|
||||
# `main` is empty on purpose, because we test the `django.setup()` step.
|
||||
# It executes the `myapp/models.py` file and should not produce anything,
|
||||
# because `reveal_type` and `reveal_locals` are patched.
|
||||
installed_apps:
|
||||
- myapp
|
||||
files:
|
||||
- path: myapp/__init__.py
|
||||
- path: myapp/models.py
|
||||
content: |
|
||||
# Will be executed during `django.setup()`:
|
||||
a = 1
|
||||
reveal_type(a)
|
||||
reveal_locals()
|
||||
Reference in New Issue
Block a user