Repository navigation
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 97.68%. The percentage of expected errors that received a diagnostic held steady at 93.44%. The number of fully passing files held steady at 109/136. |
Memory usage reportMemory usage unchanged ✅ |
charliermarsh
added a commit
that referenced
this pull request
Aug 19, 2026
## Summary
Previously, creating a dynamic class inside a string annotation could
panic because the call's AST node belongs to a separately parsed
annotation rather than the enclosing module:
```python
from types import new_class
from typing import Annotated
def example(
first: "Annotated[int, type('First', (), {})]",
second: "Annotated[int, new_class('Second', ())]",
) -> None: ...
```
Dynamic classes normally retain a scope-relative AST node index as their
identity. For calls parsed from string annotations, that index was
missing or later resolved against the wrong AST.
We now anchor those calls to the enclosing string expression and record
the call's relative source range. This preserves distinct class
identities, points diagnostics at the actual call, and handles nested
annotations without retaining absolute source positions.
Supersedes #27851.
---------
Co-authored-by: zaniebot <[email protected]>
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.
An invalid string annotation such as
x: "type('X', (), {})[int]"can panic while reporting a diagnostic for a dynamic class. The call'sNodeIndexbelongs to a separately parsed annotation, but its stored scope offset is later resolved against the module AST.Use a shared scope-relative location for dynamic-class calls. Ordinary calls retain their node offsets, while calls in string annotations retain the enclosing string's node offset and a relative source range. This restores the existing diagnostics and keeps separate calls within the same string distinct.