Commit e9ba848
[ty] Fix excess subscript argument inference for non-generic types (#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 <[email protected]>1 parent 60d4694 commit e9ba848
2 files changed
Lines changed: 9 additions & 4 deletions
File tree
- crates/ty_python_semantic
- resources/mdtest
- src/types/infer/builder
Lines changed: 0 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
677 | | - | |
678 | | - | |
679 | 677 | | |
680 | | - | |
681 | 678 | | |
682 | 679 | | |
683 | 680 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
632 | 632 | | |
633 | 633 | | |
634 | 634 | | |
635 | | - | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
636 | 644 | | |
637 | 645 | | |
638 | 646 | | |
| |||
0 commit comments