From c556668d7aeb73a9934b2666ace9b975cbc557bb Mon Sep 17 00:00:00 2001 From: Seth Yastrov Date: Fri, 28 Jan 2022 19:43:03 +0100 Subject: [PATCH] Attempt to fix 'INTERNAL ERROR using annotate'. (#753) KeyError: "Failed qualified lookup: '_AnyAttrAllowed' (fullname = 'django._AnyAttrAllowed')." https://github.com/typeddjango/django-stubs/issues/745 --- django-stubs/__init__.pyi | 7 +------ django_stubs_ext/django_stubs_ext/__init__.py | 3 ++- django_stubs_ext/django_stubs_ext/types.py | 10 ++++++++++ mypy_django_plugin/lib/fullnames.py | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 django_stubs_ext/django_stubs_ext/types.py diff --git a/django-stubs/__init__.pyi b/django-stubs/__init__.pyi index 689c4f4..2e9627b 100644 --- a/django-stubs/__init__.pyi +++ b/django-stubs/__init__.pyi @@ -1,4 +1,4 @@ -from typing import Any, Protocol +from typing import Any from .utils.version import get_version as get_version @@ -6,8 +6,3 @@ VERSION: Any __version__: str def setup(set_prefix: bool = ...) -> None: ... - -# Used internally by mypy_django_plugin. -class _AnyAttrAllowed(Protocol): - def __getattr__(self, item: str) -> Any: ... - def __setattr__(self, item: str, value: Any) -> None: ... diff --git a/django_stubs_ext/django_stubs_ext/__init__.py b/django_stubs_ext/django_stubs_ext/__init__.py index 92bc220..d82aea6 100644 --- a/django_stubs_ext/django_stubs_ext/__init__.py +++ b/django_stubs_ext/django_stubs_ext/__init__.py @@ -2,5 +2,6 @@ from .aliases import ValuesQuerySet as ValuesQuerySet from .annotations import Annotations as Annotations from .annotations import WithAnnotations as WithAnnotations from .patch import monkeypatch as monkeypatch +from .types import AnyAttrAllowed as AnyAttrAllowed -__all__ = ["monkeypatch", "ValuesQuerySet", "WithAnnotations", "Annotations"] +__all__ = ["monkeypatch", "ValuesQuerySet", "WithAnnotations", "Annotations", "AnyAttrAllowed"] diff --git a/django_stubs_ext/django_stubs_ext/types.py b/django_stubs_ext/django_stubs_ext/types.py new file mode 100644 index 0000000..8c60066 --- /dev/null +++ b/django_stubs_ext/django_stubs_ext/types.py @@ -0,0 +1,10 @@ +from typing import Any, Protocol + + +# Used internally by mypy_django_plugin. +class AnyAttrAllowed(Protocol): + def __getattr__(self, item: str) -> Any: + ... + + def __setattr__(self, item: str, value: Any) -> None: + ... diff --git a/mypy_django_plugin/lib/fullnames.py b/mypy_django_plugin/lib/fullnames.py index 1441a55..8e0a2a0 100644 --- a/mypy_django_plugin/lib/fullnames.py +++ b/mypy_django_plugin/lib/fullnames.py @@ -38,4 +38,4 @@ HTTPREQUEST_CLASS_FULLNAME = "django.http.request.HttpRequest" F_EXPRESSION_FULLNAME = "django.db.models.expressions.F" -ANY_ATTR_ALLOWED_CLASS_FULLNAME = "django._AnyAttrAllowed" +ANY_ATTR_ALLOWED_CLASS_FULLNAME = "django_stubs_ext.AnyAttrAllowed"