Skip to content

Fix descriptor semantics for initialized annotations - #4476

Open
patrickswedish wants to merge 1 commit into
facebook:mainfrom
patrickswedish:codex/fix-annotated-descriptor-semantics
Open

Fix descriptor semantics for initialized annotations#4476
patrickswedish wants to merge 1 commit into
facebook:mainfrom
patrickswedish:codex/fix-annotated-descriptor-semantics

Conversation

@patrickswedish

@patrickswedish patrickswedish commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • avoid applying descriptor protocol semantics to annotated fields initialized in recognized instance methods
  • preserve the existing class-field classification and class-level visibility behavior for unrelated annotations
  • add regression coverage for annotation plus __init__ assignment while retaining annotation-only and method-only controls

Root cause

DeclaredByAnnotation already records initialized_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 when self.field was 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 — passed
  • python test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema — formatting passed; Rust lint was blocked locally because the Windows host has no MSVC link.exe
  • git diff --check — passed
  • repository Linux, Windows, macOS, and compatibility CI rerunning on the narrowed patch

AI agent disclosure: OpenAI Codex prepared this PR; the contributor reviewed and understands the changes.

@meta-codesync

meta-codesync Bot commented Aug 8, 2026

Copy link
Copy Markdown
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.)

@codspeed-hq

codspeed-hq Bot commented Aug 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing patrickswedish:codex/fix-annotated-descriptor-semantics (1ee5a9f) with main (dd4d9f3)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

This comment has been minimized.

@patrickswedish
patrickswedish force-pushed the codex/fix-annotated-descriptor-semantics branch from a970a72 to 8bf7cab Compare August 8, 2026 22:48
@github-actions github-actions Bot added size/s and removed size/xs labels Aug 8, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size/xs and removed size/s labels Aug 9, 2026
@patrickswedish
patrickswedish force-pushed the codex/fix-annotated-descriptor-semantics branch from 7114dd4 to 448afb3 Compare August 9, 2026 00:28
@github-actions github-actions Bot added size/xs and removed size/xs labels Aug 9, 2026
@patrickswedish
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
patrickswedish force-pushed the codex/fix-annotated-descriptor-semantics branch from 448afb3 to 1ee5a9f Compare August 9, 2026 00:58
@github-actions github-actions Bot added size/xs and removed size/xs labels Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

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

@github-actions
github-actions Bot requested a review from kinto0 August 9, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Descriptor semantics are applied to annotated instance attributes based on type rather than class attribute

2 participants