python / python/mypy

When accessing a functools.cached_property through the class, mypy incorrectly treats it as a Callable.

Open
#21,825 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.