Skip to content

Commit 0602811

Browse files
committed
Add special support for @django.cached_property needed in django-stubs
1 parent e9fa89b commit 0602811

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

mypy/stubtest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,21 @@ def verify_paramspecexpr(
12561256
return
12571257

12581258

1259+
def _is_django_cached_property(runtime: Any) -> bool: # pragma: no cover
1260+
# This is a special case for
1261+
# https://docs.djangoproject.com/en/5.2/ref/utils/#django.utils.functional.cached_property
1262+
# This is needed in `django-stubs` project:
1263+
# https://github.com/typeddjango/django-stubs
1264+
try:
1265+
from django.utils.functional import cached_property # type: ignore[import-not-found]
1266+
except Exception:
1267+
return False
1268+
try:
1269+
return isinstance(runtime, cached_property) and bool(runtime.func)
1270+
except Exception:
1271+
return False
1272+
1273+
12591274
def _verify_readonly_property(stub: nodes.Decorator, runtime: Any) -> Iterator[str]:
12601275
assert stub.func.is_property
12611276
if isinstance(runtime, property):
@@ -1264,6 +1279,9 @@ def _verify_readonly_property(stub: nodes.Decorator, runtime: Any) -> Iterator[s
12641279
if isinstance(runtime, functools.cached_property):
12651280
yield from _verify_final_method(stub.func, runtime.func, MISSING)
12661281
return
1282+
if _is_django_cached_property(runtime):
1283+
yield from _verify_final_method(stub.func, runtime.func, MISSING)
1284+
return
12671285
if inspect.isdatadescriptor(runtime):
12681286
# It's enough like a property...
12691287
return

0 commit comments

Comments
 (0)