* Fix CI

* Fix CI

* Fix CI

* Fix CI

* APply black

* APply black

* Fix mypy

* Fix mypy errors in django-stubs

* Fix format

* Fix plugin

* Do not patch builtins by default

* Fix mypy

* Only run mypy on 3.10 for now

* Only run mypy on 3.10 for now

* WHAT THE HELL

* Enable strict mode in mypy

* Enable strict mode in mypy

* Fix tests

* Fix tests

* Debug

* Debug

* Fix tests

* Fix tests

* Add TYPE_CHECKING debug

* Caching maybe?

* Caching maybe?

* Try explicit `${{ matrix.python-version }}`

* Remove debug

* Fix typing

* Finally
This commit is contained in:
Nikita Sobolev
2022-08-26 13:22:55 +03:00
committed by GitHub
parent d2bfd3710b
commit 0bb1182c42
80 changed files with 223 additions and 582 deletions

View File

@@ -1,3 +1,4 @@
import builtins
from typing import Any, Generic, Iterable, List, Optional, Tuple, Type, TypeVar
from django import VERSION as VERSION
@@ -17,6 +18,8 @@ from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import DeletionMixin, FormMixin
from django.views.generic.list import MultipleObjectMixin
__all__ = ["monkeypatch"]
_T = TypeVar("_T")
_VersionSpec = Tuple[int, int]
@@ -67,7 +70,7 @@ _need_generic: List[MPGeneric[Any]] = [
]
def monkeypatch(extra_classes: Optional[Iterable[type]] = None) -> None:
def monkeypatch(extra_classes: Optional[Iterable[type]] = None, include_builtins: bool = True) -> None:
"""Monkey patch django as necessary to work properly with mypy."""
# Add the __class_getitem__ dunder.
@@ -81,5 +84,7 @@ def monkeypatch(extra_classes: Optional[Iterable[type]] = None) -> None:
for cls in extra_classes:
cls.__class_getitem__ = classmethod(lambda cls, *args, **kwargs: cls) # type: ignore[attr-defined]
__all__ = ["monkeypatch"]
# Add `reveal_type` and `reveal_locals` helpers if needed:
if include_builtins:
builtins.reveal_type = lambda _: None
builtins.reveal_locals = lambda: None

View File

@@ -1,10 +1,7 @@
import sys
from typing import Any
if sys.version_info < (3, 8):
from typing_extensions import Protocol
else:
from typing import Protocol
from typing_extensions import Protocol
# Used internally by mypy_django_plugin.
class AnyAttrAllowed(Protocol):