Skip to content

Commit 39886cf

Browse files
committed
[ty] Make infer_subscript_expression_types a method on Type
1 parent 7947ac3 commit 39886cf

5 files changed

Lines changed: 923 additions & 586 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+
```

crates/ty_python_semantic/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ mod visitor;
122122
mod definition;
123123
#[cfg(test)]
124124
mod property_tests;
125+
mod subscript;
125126

126127
pub fn check_types(db: &dyn Db, file: File) -> Vec<Diagnostic> {
127128
let _span = tracing::trace_span!("check_types", ?file).entered();

crates/ty_python_semantic/src/types/generics.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -705,27 +705,6 @@ impl<'db> GenericContext<'db> {
705705
}
706706
}
707707

708-
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
709-
pub(super) enum LegacyGenericBase {
710-
Generic,
711-
Protocol,
712-
}
713-
714-
impl LegacyGenericBase {
715-
const fn as_str(self) -> &'static str {
716-
match self {
717-
Self::Generic => "Generic",
718-
Self::Protocol => "Protocol",
719-
}
720-
}
721-
}
722-
723-
impl Display for LegacyGenericBase {
724-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
725-
f.write_str(self.as_str())
726-
}
727-
}
728-
729708
/// An assignment of a specific type to each type variable in a generic scope.
730709
///
731710
/// TODO: Handle nested specializations better, with actual parent links to the specialization of

0 commit comments

Comments
 (0)