When accessing a functools.cached_property through the class, mypy incorrectly treats it as a Callable.
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When accessing a functools.cached_property through the class, mypy incorrectly treats it as a Callable.
To Reproduce
from functools import cached_property
class A:
@cached_property
def value(self) -> int:
return 1
@classmethod
def name(cls) -> str:
return cls.value.attrname
Expected Behavior
mypy should know that A.value is a cached_property, not a function.
Actual Behavior
error: "Callable[[A], int]" has no attribute "attrname" [attr-defined]
Environment
- Mypy version used: 2.3.0
- Python version used: 3.12
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the issue's cached_property reproduction with mypy 2.3.0 and trace how class access to functools.cached_property is inferred. The fix is complete when A.value is recognized as a cached_property rather than a Callable, allowing attrname access without an error; add a regression test for this example if the test location is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100