diff --git a/mypy/stubtest.py b/mypy/stubtest.py index ab29d9dca4b8..3fe28d416727 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -1256,6 +1256,19 @@ def verify_paramspecexpr( return +def _is_django_cached_property(runtime: Any) -> bool: # pragma: no cover + # This is a special case for + # https://docs.djangoproject.com/en/5.2/ref/utils/#django.utils.functional.cached_property + # This is needed in `django-stubs` project: + # https://github.com/typeddjango/django-stubs + if type(runtime).__name__ != "cached_property": + return False + try: + return bool(runtime.func) + except Exception: + return False + + def _verify_readonly_property(stub: nodes.Decorator, runtime: Any) -> Iterator[str]: assert stub.func.is_property if isinstance(runtime, property): @@ -1264,6 +1277,9 @@ def _verify_readonly_property(stub: nodes.Decorator, runtime: Any) -> Iterator[s if isinstance(runtime, functools.cached_property): yield from _verify_final_method(stub.func, runtime.func, MISSING) return + if _is_django_cached_property(runtime): + yield from _verify_final_method(stub.func, runtime.func, MISSING) + return if inspect.isdatadescriptor(runtime): # It's enough like a property... return