Skip to content

Fix cached_property access through classes - #21831

Draft
aryansk wants to merge 1 commit into
python:masterfrom
aryansk:codex/issue-21825-cached-property
Draft

Fix cached_property access through classes#21831
aryansk wants to merge 1 commit into
python:masterfrom
aryansk:codex/issue-21825-cached-property

Conversation

@aryansk

@aryansk aryansk commented Aug 10, 2026

Copy link
Copy Markdown

Summary

Fixes #21825.

functools.cached_property.__get__ returns the descriptor when accessed through a class. Mypy now preserves that behavior for class-level access, while instance access continues to use the cached property's return type. The decorator marker is retained in serialized nodes and the cache format version is bumped so stale caches cannot misinterpret the new field.

Evidence

  • test-data/unit/check-functools.test covers class access from both A.value and a classmethod, including .attrname.
  • uv run --with mypy-extensions --with pytest --with pytest-xdist --with lxml python3 -m pytest -q mypy/test/testcheck.py -k 'check-functools' (31 passed)
  • uv run --with mypy-extensions --with pytest --with filelock --with psutil --with types-psutil --with tomli --with lxml python3 -m mypy --config-file mypy_self_check.ini -p mypy (clean)
  • uv run --with pre-commit pre-commit run --files mypy/checkmember.py mypy/nodes.py mypy/semanal.py mypy/cache.py test-data/unit/check-functools.test (passed)
  • git diff --check

No maintainer-only, legal, or contributor-account action is required.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant