[ty] Fix excess subscript argument inference for non-generic types#24354
Merged
AlexWaygood merged 1 commit intomainfrom Apr 9, 2026
Merged
[ty] Fix excess subscript argument inference for non-generic types#24354AlexWaygood merged 1 commit intomainfrom
AlexWaygood merged 1 commit intomainfrom
Conversation
…on-generic types In `list[int][0]`, the `[0]` subscript was incorrectly parsed as a type expression because `infer_explicit_callable_specialization_impl` always called `infer_type_expression` for excess type arguments. When the type has no type variables (i.e. is fully specialized), excess arguments should be inferred as regular expressions instead. https://claude.ai/code/session_01Kte64hrkmjVtduw18NpToE
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 86.76%. The percentage of expected errors that received a diagnostic held steady at 81.53%. The number of fully passing files held steady at 70/132. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
0 | 40 | 0 |
invalid-return-type |
0 | 1 | 0 |
invalid-type-form |
0 | 1 | 0 |
| Total | 0 | 42 | 0 |
Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.
Raw diff:
sympy (https://github.com/sympy/sympy)
- sympy/vector/implicitregion.py:130:49 error[invalid-type-form] Int literals are not allowed in this context in a type expression
Member
Author
|
This one is purely Claude-authored but I think it's correct? I've stared at it for quite a while now, anyway. |
sharkdp
approved these changes
Apr 9, 2026
Contributor
sharkdp
left a comment
There was a problem hiding this comment.
I guess this might need to be reworked once we add support for TypeVarTuple, but it looks good for now. Thanks.
ibraheemdev
pushed a commit
that referenced
this pull request
Apr 15, 2026
…24354) ## Summary When a non-generic type (like `list[int]`) is subscripted with excess arguments (e.g., `list[int][0]`), the excess arguments should be inferred as regular expressions, not type expressions. This prevents spurious "Int literals are not allowed in this context" errors. The fix checks if the base type has any type variables. If `typevars_len == 0`, we know it's not a generic type, so excess subscript arguments are inferred using `infer_expression()` with a default context instead of `infer_type_expression()`. This allows us to properly handle non-type values in excess subscripts while still reporting the primary error that the type is not subscriptable. This change also eliminates a duplicate error message in the test case `list[int][0]`, reducing the error count from two to one. ## Test Plan mdtests updated Co-authored-by: Claude <noreply@anthropic.com>
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
When a non-generic type (like
list[int]) is subscripted with excess arguments (e.g.,list[int][0]), the excess arguments should be inferred as regular expressions, not type expressions. This prevents spurious "Int literals are not allowed in this context" errors.The fix checks if the base type has any type variables. If
typevars_len == 0, we know it's not a generic type, so excess subscript arguments are inferred usinginfer_expression()with a default context instead ofinfer_type_expression(). This allows us to properly handle non-type values in excess subscripts while still reporting the primary error that the type is not subscriptable.This change also eliminates a duplicate error message in the test case
list[int][0], reducing the error count from two to one.Test Plan
mdtests updated