← Open Source & Engineering Work
Meta · PyreflyMerged Upstream

Correct Descriptor Semantics for Initialized Annotations

A 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.

Patrick Ribbsaeter open-source contribution to Meta Pyrefly PR #4476 merged upstream

#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 field was actually initialized on self inside __init__. That produced incorrect descriptor semantics for a valid instance-field pattern.

02 · Technical response

What changed

  1. 01Traced the behavior to DeclaredByAnnotation and its existing initialized_in_recognized_method signal.
  2. 02Used that signal only to skip descriptor construction for the annotated-and-method-initialized case.
  3. 03Preserved unrelated class-field visibility and constructor behavior.
  4. 04Added regression coverage for annotation plus __init__ assignment while retaining annotation-only and method-only controls.

03 · Verified outcome

Evidence-backed result

  • 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 target semantics were corrected without broad field-classification changes.

04 · Public record

Source evidence

RustPythonPyreflyType CheckingLanguage Tooling

Independent open-source engineering by Patrick Ribbsaeter. Company and project names identify the public repository and maintainer context only. No employment, client, vendor, or partnership relationship is implied unless explicitly stated.