Repository navigation
Conversation
charliermarsh
added a commit
that referenced
this pull request
Aug 19, 2026
## Summary
Previously, we inferred an invalid subscript's value before checking
whether it was a valid type-expression operand. Inside a string
annotation, this could evaluate expressions that are absent from the
semantic index, panic on assignment expressions, or emit cascading
unresolved-reference diagnostics:
```python
value: "(lambda default=(name := int): None)[int]"
other: "TypedDict('T', {}, extra_items=missing)[int]"
```
We now infer invalid subscript operands only when annotations execute at
runtime. String annotations instead report the existing
`invalid-type-form` diagnostic without evaluating their invalid
children, matching existing error-recovery behavior in both Python and
stub files.
Supersedes #27852.
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.
Invalid string annotations containing a lambda default, or a functional
TypedDictwithextra_itemsin a stub, can panic during name lookup. These paths overwriteInStringAnnotationwhile selecting how to resolve names, so inference expects annotation-only nodes to exist in the module's semantic index.Preserve the string-annotation state while inferring lambda defaults, and let the existing annotation-expression helper choose the appropriate state for
extra_items.