Skip to content

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

Description

@krisislis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions