Skip to content

Commit 098cc9d

Browse files
committed
[ty] Make infer_subscript_expression_types a method on Type
1 parent 5949fa0 commit 098cc9d

4 files changed

Lines changed: 874 additions & 580 deletions

File tree

crates/ty_python_semantic/resources/mdtest/subscript/tuple.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,36 @@ def test4(val: Intersection[tuple[Foo], tuple[Bar]]):
432432
# TODO: should be `Foo & Bar`
433433
reveal_type(val[0]) # revealed: @Todo(Subscript expressions with intersections)
434434
```
435+
436+
## Intersection slice access
437+
438+
```py
439+
from ty_extensions import Intersection
440+
441+
class A: ...
442+
class B: ...
443+
class C: ...
444+
class D: ...
445+
446+
def f(
447+
x: tuple[A, B],
448+
y: tuple[C, D],
449+
z: Intersection[tuple[A, B], tuple[C, D]],
450+
):
451+
reveal_type(x[1:]) # revealed: tuple[B]
452+
reveal_type(y[1:]) # revealed: tuple[D]
453+
# TODO: should be `tuple[B] & tuple[D]`
454+
reveal_type(z[1:]) # revealed: @Todo(Subscript expressions with intersections)
455+
```
456+
457+
```py
458+
class A: ...
459+
class B: ...
460+
class C: ...
461+
462+
def g(x: tuple[A, B]):
463+
reveal_type(x[1:]) # revealed: tuple[B]
464+
if isinstance(x, C):
465+
# TODO: should be `tuple[B]`
466+
reveal_type(x[1:]) # revealed: @Todo(Subscript expressions with intersections)
467+
```

0 commit comments

Comments
 (0)