Repository navigation
Fix circular TypeAliasType references in TypedDict and NamedTuple fields - #11815
Open
crypt0lith wants to merge 1 commit into
Open
crypt0lith wants to merge 1 commit into
crypt0lith wants to merge 1 commit into
Conversation
Contributor
|
Compared candidate View the full release history charts with the base and PR results. Execution time historyPeak memory historyType checker benchmark🟢 No performance regressions detected. Regression threshold:
Pyright stats
|
crypt0lith
temporarily deployed
to
github-pages
October 1, 2026 19:28 — with
GitHub Actions
Inactive
Collaborator
🟢 Pyright CLI QA —
|
When the value of a TypeAliasType call refers to TypedDict or NamedTuple classes whose fields refer back to the alias, evaluating the alias builds those classes' fields, and the fields look up the alias while it is still being evaluated. getTypeOfTypeAliasCommon creates a placeholder for this, but never registers it as a partial type for a TypeAliasType call, because the binder attaches no declaration to the target of an assignment. The lookup then fails the recursion check in getTypeOfSymbolForDecls and produces Unknown, which is reported as a variable in a type expression. The failed check also invalidates the symbols being resolved above it, which discards the declared type of a TypedDict field. Find the declaration through the alias symbol when the name node has none, and check for a partial type in getTypeOfSymbolForDecls before the recursion check, as getDeclaredTypeOfSymbol already does. Adds typeAliasType3.py, which reveals the field types of TypedDict and NamedTuple classes that refer to each other through a TypeAliasType. Fixes microsoft#11810.
crypt0lith
force-pushed
the
fix/typealiastype-reentrancy-cycle
branch
from
November 1, 2026 02:27
ab0c5c6 to
2fb2b9e
Compare
This branch was previously deployed
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
Fixes #11810.
Pyright reports a field annotation that refers back to the alias as a variable in a type expression, and discards the declared type of a TypedDict field.
Root cause
Evaluating the value of a
TypeAliasTypecall builds the fields of the TypedDict or NamedTuple classes it refers to, and those fields look up the alias while it is still being evaluated.getTypeOfTypeAliasCommoncreates a placeholder for this, but registers it as a partial type only when the alias name has a declaration, and the binder attaches no declaration to the target of an assignment. The lookup then fails the recursion check ingetTypeOfSymbolForDeclsand producesUnknown. The failed check also invalidates the symbols being resolved above it, including the field whose annotation is being evaluated.Fix
getTypeOfTypeAliasCommon, find the declaration through the alias symbol when the name node has none.getTypeOfSymbolForDecls, check for a partial type before the recursion check, asgetDeclaredTypeOfSymbolalready does.Test
Adds a test sample
typeAliasType3.pythat reveals the field types of TypedDict and NamedTuple classes that refer to each other through aTypeAliasType. Without the fix, it reports 3 errors.