Skip to content

Resolve nested class forward references in annotations - #4513

Open
cakeni wants to merge 1 commit into
facebook:mainfrom
cakeni:fix/nested-class-forward-ref
Open

Resolve nested class forward references in annotations#4513
cakeni wants to merge 1 commit into
facebook:mainfrom
cakeni:fix/nested-class-forward-ref

Conversation

@cakeni

@cakeni cakeni commented Aug 11, 2026

Copy link
Copy Markdown

Summary

Allow postponed and quoted annotations in a class body to resolve a nested class declared later in that same body. The deferred class-body lookup now records whether same-class forward resolution is legal, while ordinary runtime reads keep the existing inherited-only behavior.

Tests cover the future-annotations regression on Python 3.13, both annotations before and after the nested class declaration, and a runtime read that must still report unknown-name.

Fixes #4410

Test Plan

  • cargo +stable-x86_64-pc-windows-gnu test -p pyrefly --lib test_nested_class_ -- --nocapture (9 passed)
  • python test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
  • cargo fmt --all -- --check
  • git diff --check

@meta-codesync

meta-codesync Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D115588128. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

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

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.

Cannot resolve forward ref to nested class in another attr of enclosing class

2 participants