Repository navigation
Fix descriptor __get__/__set__ access on named tuple attributes - #22213
Open
VedantBhayani wants to merge 1 commit into
Open
VedantBhayani wants to merge 1 commit into
VedantBhayani wants to merge 1 commit into
Conversation
Named tuples are represented as TupleType, but analyze_descriptor_access() returned early for any non-Instance type, so a __get__ or __set__ override defined on a named tuple class was ignored when the named tuple was used as a class attribute descriptor. Map TupleType to its fallback instance before the Instance check, matching what regular member access already does. Fixes python#22193.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Named tuples are represented as
TupleType, butanalyze_descriptor_access()returned early for any non-Instancetype. As a result, a__get__(or__set__) override defined in aNamedTupleclass body was ignored when the named tuple was used as a class attribute descriptor:reveal_type(SomeClass.tuple_descr)produced the raw tuple fallback instead of the__get__return type.Map
TupleTypeto its fallback instance before theInstancecheck, matching how regular tuple member access already handles this viatuple_fallback().Adds
testDescriptorGetNamedTupleandtestDescriptorSetNamedTupleregression tests covering both the class-attribute and instance-attribute access paths.Fixes #22193.
Local test runs:
pytest mypy/test/testcheck.py— 8319 passed, 16 skipped, 7 xfailedpytest mypy/test/testfinegrained.py— 754 passed, 28 skippedpython -m mypy --config-file mypy_self_check.ini -p mypy— Success: no issues found in 196 source filesruff check,ruff format --check,black --check— cleanNote: this contribution was developed with LLM assistance under human review.