Fix descriptor semantics for initialized annotations - #4476
Open
patrickswedish wants to merge 1 commit into
Open
Fix descriptor semantics for initialized annotations#4476patrickswedish wants to merge 1 commit into
patrickswedish wants to merge 1 commit into
Conversation
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D115325693. (Because this pull request was imported automatically, there will not be any future comments.) |
Merging this PR will not alter performance
Comparing Footnotes
|
This comment has been minimized.
This comment has been minimized.
patrickswedish
force-pushed
the
codex/fix-annotated-descriptor-semantics
branch
from
August 8, 2026 22:48
a970a72 to
8bf7cab
Compare
This comment has been minimized.
This comment has been minimized.
patrickswedish
force-pushed
the
codex/fix-annotated-descriptor-semantics
branch
from
August 9, 2026 00:28
7114dd4 to
448afb3
Compare
patrickswedish
marked this pull request as ready for review
August 9, 2026 00:56
Preserve data-descriptor behavior for setters and deleters while preventing getter-only instance annotations from being treated as class descriptors.
patrickswedish
force-pushed
the
codex/fix-annotated-descriptor-semantics
branch
from
August 9, 2026 00:58
448afb3 to
1ee5a9f
Compare
|
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.
Summary
__init__assignment while retaining annotation-only and method-only controlsRoot cause
DeclaredByAnnotationalready recordsinitialized_in_recognized_method, but descriptor detection did not consult that signal. An annotation whose type implements__get__was therefore treated as a class-installed descriptor even whenself.fieldwas initialized in__init__.The fix uses that signal only to skip descriptor construction for the annotated-and-method-initialized case. It intentionally leaves the field's existing initialization classification unchanged, avoiding unrelated class-visibility and constructor behavior changes.
Fixes #4471
Validation
cargo fmt --all -- --check— passedpython test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema— formatting passed; Rust lint was blocked locally because the Windows host has no MSVClink.exegit diff --check— passedAI agent disclosure: OpenAI Codex prepared this PR; the contributor reviewed and understands the changes.