Correct Descriptor Semantics for Initialized Annotations in Meta Pyrefly
A directly shipped Meta Pyrefly contribution that stops annotation-only descriptor inference from misclassifying instance fields initialized in recognized methods. PR #4476 was imported into Meta’s internal workflow and shipped upstream as commit 8387bfd.

#4476
public PR
8387bfd
upstream commit
2
files changed
+21 / −2
focused diff
01 · Engineering problem
The failure mode
Pyrefly could treat an annotated instance attribute as a class-installed descriptor whenever its type implemented __get__, even when the attribute was actually initialized on self inside __init__. That produced incorrect descriptor semantics for a valid instance-field pattern.
02 · Technical response
What changed
- 01Traced the field classification to DeclaredByAnnotation and the existing initialized_in_recognized_method signal.
- 02Used that signal only to skip descriptor construction for the annotated-and-method-initialized case.
- 03Preserved unrelated class-field visibility and constructor behavior rather than broadening the change.
- 04Added regression coverage for annotation plus __init__ assignment while retaining annotation-only and method-only controls.
03 · Verified outcome
Evidence, not implication
- ✓Meta imported the contribution into its internal development workflow.
- ✓The final change shipped upstream in facebook/pyrefly at commit 8387bfded3736532e1b6c1c124264711ea0c50bc.
- ✓mypy_primer reported no type-check result changes across its open-source corpus after the narrowed patch.
- ✓The contribution corrected the target semantics without changing unrelated field classification behavior.
04 · Public record
Source evidence
Independent engineering and open-source work by Patrick Ribbsaeter / Ribbsaeter Systems. References to maintainers, repositories, or companies identify the public technical context only. No employment, client, vendor, or partnership relationship is implied unless explicitly stated.