Commit 6759dbd
authored
Infer generic type arguments for slice expressions (python#18160)
Fixes python#18149
Slices were made generic in
python/typeshed#11637. Currently, all slice
expressions are inferred to have type `slice[Any, Any, Any]`. This PR
fills in the generic type arguments more appropriately using
start/stop/stride expression types.
Given
```python
class Foo:
def __getitem__[T](self, item: T) -> T: return item
x = Foo()
reveal_type(x[1:])
```
Before:
```none
main.py:5: note: Revealed type is "builtins.slice[Any, Any, Any]"
```
After:
```none
main.py:5: note: Revealed type is "builtins.slice[builtins.int, None, None]"
```1 parent 8ef2197 commit 6759dbd
2 files changed
+7
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5612 | 5612 | | |
5613 | 5613 | | |
5614 | 5614 | | |
| 5615 | + | |
5615 | 5616 | | |
5616 | 5617 | | |
5617 | 5618 | | |
5618 | 5619 | | |
5619 | | - | |
| 5620 | + | |
| 5621 | + | |
| 5622 | + | |
| 5623 | + | |
5620 | 5624 | | |
5621 | 5625 | | |
5622 | 5626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1178 | 1178 | | |
1179 | 1179 | | |
1180 | 1180 | | |
1181 | | - | |
1182 | | - | |
| 1181 | + | |
| 1182 | + | |
1183 | 1183 | | |
1184 | 1184 | | |
1185 | 1185 | | |
| |||
0 commit comments