Skip to content

Commit d1bb10a

Browse files
authored
[ty] Understand classes that inherit from subscripted Protocol[] as generic (#17832)
1 parent 2370297 commit d1bb10a

File tree

35 files changed

+451
-183
lines changed

35 files changed

+451
-183
lines changed

crates/ruff_benchmark/benches/ty.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,29 @@ type KeyDiagnosticFields = (
5959
Severity,
6060
);
6161

62-
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[];
62+
static EXPECTED_TOMLLIB_DIAGNOSTICS: &[KeyDiagnosticFields] = &[
63+
(
64+
DiagnosticId::lint("invalid-argument-type"),
65+
Some("/src/tomllib/_parser.py"),
66+
Some(8224..8254),
67+
"Argument to this function is incorrect",
68+
Severity::Error,
69+
),
70+
(
71+
DiagnosticId::lint("invalid-argument-type"),
72+
Some("/src/tomllib/_parser.py"),
73+
Some(16914..16948),
74+
"Argument to this function is incorrect",
75+
Severity::Error,
76+
),
77+
(
78+
DiagnosticId::lint("invalid-argument-type"),
79+
Some("/src/tomllib/_parser.py"),
80+
Some(17319..17363),
81+
"Argument to this function is incorrect",
82+
Severity::Error,
83+
),
84+
];
6385

6486
fn tomllib_path(file: &TestFile) -> SystemPathBuf {
6587
SystemPathBuf::from("src").join(file.name())

crates/ty_python_semantic/resources/mdtest/annotations/self.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class Shape:
3333
reveal_type(self) # revealed: Unknown
3434
return self
3535

36-
reveal_type(Shape().nested_type()) # revealed: @Todo(specialized non-generic class)
36+
# TODO: should be `list[Shape]`
37+
reveal_type(Shape().nested_type()) # revealed: list[Self]
38+
3739
reveal_type(Shape().nested_func()) # revealed: Shape
3840

3941
class Circle(Shape):

crates/ty_python_semantic/resources/mdtest/annotations/starred.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Ts = TypeVarTuple("Ts")
1414

1515
def append_int(*args: *Ts) -> tuple[*Ts, int]:
1616
# TODO: tuple[*Ts]
17-
reveal_type(args) # revealed: tuple
17+
reveal_type(args) # revealed: tuple[Unknown, ...]
1818

1919
return (*args, 1)
2020

crates/ty_python_semantic/resources/mdtest/annotations/stdlib_typing_aliases.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,22 @@ def f(
3030
ordered_dict_bare: typing.OrderedDict,
3131
ordered_dict_parametrized: typing.OrderedDict[int, str],
3232
):
33-
# TODO: revealed: list[Unknown]
34-
reveal_type(list_bare) # revealed: list
33+
reveal_type(list_bare) # revealed: list[Unknown]
3534
# TODO: revealed: list[int]
36-
reveal_type(list_parametrized) # revealed: list
35+
reveal_type(list_parametrized) # revealed: list[Unknown]
3736

3837
reveal_type(dict_bare) # revealed: dict[Unknown, Unknown]
3938
# TODO: revealed: dict[int, str]
4039
reveal_type(dict_parametrized) # revealed: dict[Unknown, Unknown]
4140

42-
# TODO: revealed: set[Unknown]
43-
reveal_type(set_bare) # revealed: set
41+
reveal_type(set_bare) # revealed: set[Unknown]
4442
# TODO: revealed: set[int]
45-
reveal_type(set_parametrized) # revealed: set
43+
reveal_type(set_parametrized) # revealed: set[Unknown]
4644

4745
# TODO: revealed: frozenset[Unknown]
48-
reveal_type(frozen_set_bare) # revealed: frozenset
46+
reveal_type(frozen_set_bare) # revealed: frozenset[Unknown]
4947
# TODO: revealed: frozenset[str]
50-
reveal_type(frozen_set_parametrized) # revealed: frozenset
48+
reveal_type(frozen_set_parametrized) # revealed: frozenset[Unknown]
5149

5250
reveal_type(chain_map_bare) # revealed: ChainMap[Unknown, Unknown]
5351
# TODO: revealed: ChainMap[str, int]
@@ -61,10 +59,9 @@ def f(
6159
# TODO: revealed: defaultdict[str, int]
6260
reveal_type(default_dict_parametrized) # revealed: defaultdict[Unknown, Unknown]
6361

64-
# TODO: revealed: deque[Unknown]
65-
reveal_type(deque_bare) # revealed: deque
62+
reveal_type(deque_bare) # revealed: deque[Unknown]
6663
# TODO: revealed: deque[str]
67-
reveal_type(deque_parametrized) # revealed: deque
64+
reveal_type(deque_parametrized) # revealed: deque[Unknown]
6865

6966
reveal_type(ordered_dict_bare) # revealed: OrderedDict[Unknown, Unknown]
7067
# TODO: revealed: OrderedDict[int, str]
@@ -84,26 +81,23 @@ import typing
8481

8582
class ListSubclass(typing.List): ...
8683

87-
# TODO: generic protocols
88-
# revealed: tuple[<class 'ListSubclass'>, <class 'list'>, <class 'MutableSequence'>, <class 'Sequence'>, <class 'Reversible'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, <class 'object'>]
84+
# revealed: tuple[<class 'ListSubclass'>, <class 'list[Unknown]'>, <class 'MutableSequence[Unknown]'>, <class 'Sequence[Unknown]'>, <class 'Reversible[Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
8985
reveal_type(ListSubclass.__mro__)
9086

9187
class DictSubclass(typing.Dict): ...
9288

93-
# TODO: generic protocols
94-
# revealed: tuple[<class 'DictSubclass'>, <class 'dict[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, typing.Generic[_KT, _VT_co], <class 'object'>]
89+
# TODO: should not have multiple `Generic[]` elements
90+
# revealed: tuple[<class 'DictSubclass'>, <class 'dict[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], typing.Generic[_KT, _VT_co], <class 'object'>]
9591
reveal_type(DictSubclass.__mro__)
9692

9793
class SetSubclass(typing.Set): ...
9894

99-
# TODO: generic protocols
100-
# revealed: tuple[<class 'SetSubclass'>, <class 'set'>, <class 'MutableSet'>, <class 'AbstractSet'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, <class 'object'>]
95+
# revealed: tuple[<class 'SetSubclass'>, <class 'set[Unknown]'>, <class 'MutableSet[Unknown]'>, <class 'AbstractSet[Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
10196
reveal_type(SetSubclass.__mro__)
10297

10398
class FrozenSetSubclass(typing.FrozenSet): ...
10499

105-
# TODO: generic protocols
106-
# revealed: tuple[<class 'FrozenSetSubclass'>, <class 'frozenset'>, <class 'AbstractSet'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, <class 'object'>]
100+
# revealed: tuple[<class 'FrozenSetSubclass'>, <class 'frozenset[Unknown]'>, <class 'AbstractSet[Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
107101
reveal_type(FrozenSetSubclass.__mro__)
108102

109103
####################
@@ -112,31 +106,30 @@ reveal_type(FrozenSetSubclass.__mro__)
112106

113107
class ChainMapSubclass(typing.ChainMap): ...
114108

115-
# TODO: generic protocols
116-
# revealed: tuple[<class 'ChainMapSubclass'>, <class 'ChainMap[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, typing.Generic[_KT, _VT_co], <class 'object'>]
109+
# TODO: should not have multiple `Generic[]` elements
110+
# revealed: tuple[<class 'ChainMapSubclass'>, <class 'ChainMap[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], typing.Generic[_KT, _VT_co], <class 'object'>]
117111
reveal_type(ChainMapSubclass.__mro__)
118112

119113
class CounterSubclass(typing.Counter): ...
120114

121-
# TODO: Should be (CounterSubclass, Counter, dict, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
122-
# revealed: tuple[<class 'CounterSubclass'>, <class 'Counter[Unknown]'>, <class 'dict[Unknown, int]'>, <class 'MutableMapping[Unknown, int]'>, <class 'Mapping[Unknown, int]'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, typing.Generic[_KT, _VT_co], typing.Generic[_T], <class 'object'>]
115+
# TODO: Should have one `Generic[]` element, not three(!)
116+
# revealed: tuple[<class 'CounterSubclass'>, <class 'Counter[Unknown]'>, <class 'dict[Unknown, int]'>, <class 'MutableMapping[Unknown, int]'>, <class 'Mapping[Unknown, int]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], typing.Generic[_KT, _VT_co], typing.Generic[_T], <class 'object'>]
123117
reveal_type(CounterSubclass.__mro__)
124118

125119
class DefaultDictSubclass(typing.DefaultDict): ...
126120

127-
# TODO: Should be (DefaultDictSubclass, defaultdict, dict, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
128-
# revealed: tuple[<class 'DefaultDictSubclass'>, <class 'defaultdict[Unknown, Unknown]'>, <class 'dict[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, typing.Generic[_KT, _VT_co], <class 'object'>]
121+
# TODO: Should not have multiple `Generic[]` elements
122+
# revealed: tuple[<class 'DefaultDictSubclass'>, <class 'defaultdict[Unknown, Unknown]'>, <class 'dict[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], typing.Generic[_KT, _VT_co], <class 'object'>]
129123
reveal_type(DefaultDictSubclass.__mro__)
130124

131125
class DequeSubclass(typing.Deque): ...
132126

133-
# TODO: generic protocols
134-
# revealed: tuple[<class 'DequeSubclass'>, <class 'deque'>, <class 'MutableSequence'>, <class 'Sequence'>, <class 'Reversible'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, <class 'object'>]
127+
# revealed: tuple[<class 'DequeSubclass'>, <class 'deque[Unknown]'>, <class 'MutableSequence[Unknown]'>, <class 'Sequence[Unknown]'>, <class 'Reversible[Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], <class 'object'>]
135128
reveal_type(DequeSubclass.__mro__)
136129

137130
class OrderedDictSubclass(typing.OrderedDict): ...
138131

139-
# TODO: Should be (OrderedDictSubclass, OrderedDict, dict, MutableMapping, Mapping, Collection, Sized, Iterable, Container, Generic, object)
140-
# revealed: tuple[<class 'OrderedDictSubclass'>, <class 'OrderedDict[Unknown, Unknown]'>, <class 'dict[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection'>, <class 'Iterable'>, <class 'Container'>, @Todo(`Protocol[]` subscript), typing.Generic, typing.Generic[_KT, _VT_co], <class 'object'>]
132+
# TODO: Should not have multiple `Generic[]` elements
133+
# revealed: tuple[<class 'OrderedDictSubclass'>, <class 'OrderedDict[Unknown, Unknown]'>, <class 'dict[Unknown, Unknown]'>, <class 'MutableMapping[Unknown, Unknown]'>, <class 'Mapping[Unknown, Unknown]'>, <class 'Collection[Unknown]'>, <class 'Iterable[Unknown]'>, <class 'Container[Unknown]'>, typing.Protocol[_T_co], typing.Generic[_T_co], typing.Generic[_KT, _VT_co], <class 'object'>]
141134
reveal_type(OrderedDictSubclass.__mro__)
142135
```

crates/ty_python_semantic/resources/mdtest/annotations/unsupported_special_forms.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ Alias: TypeAlias = int
1616

1717
def f(*args: Unpack[Ts]) -> tuple[Unpack[Ts]]:
1818
# TODO: should understand the annotation
19-
reveal_type(args) # revealed: tuple
19+
reveal_type(args) # revealed: tuple[Unknown, ...]
2020

2121
reveal_type(Alias) # revealed: @Todo(Support for `typing.TypeAlias`)
2222

2323
def g() -> TypeGuard[int]: ...
2424
def h() -> TypeIs[int]: ...
2525
def i(callback: Callable[Concatenate[int, P], R_co], *args: P.args, **kwargs: P.kwargs) -> R_co:
2626
# TODO: should understand the annotation
27-
reveal_type(args) # revealed: tuple
27+
reveal_type(args) # revealed: tuple[Unknown, ...]
2828
reveal_type(kwargs) # revealed: dict[str, @Todo(Support for `typing.ParamSpec`)]
2929
return callback(42, *args, **kwargs)
3030

crates/ty_python_semantic/resources/mdtest/assignment/annotations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ reveal_type(d) # revealed: tuple[tuple[str, str], tuple[int, int]]
6161
reveal_type(e) # revealed: @Todo(full tuple[...] support)
6262
reveal_type(f) # revealed: @Todo(full tuple[...] support)
6363
reveal_type(g) # revealed: @Todo(full tuple[...] support)
64-
reveal_type(h) # revealed: tuple[@Todo(specialized non-generic class), @Todo(specialized non-generic class)]
64+
reveal_type(h) # revealed: tuple[list[int], list[int]]
6565

6666
reveal_type(i) # revealed: tuple[str | int, str | int]
6767
reveal_type(j) # revealed: tuple[str | int]
@@ -76,7 +76,7 @@ a: tuple[()] = (1, 2)
7676
# error: [invalid-assignment] "Object of type `tuple[Literal["foo"]]` is not assignable to `tuple[int]`"
7777
b: tuple[int] = ("foo",)
7878

79-
# error: [invalid-assignment] "Object of type `tuple[list, Literal["foo"]]` is not assignable to `tuple[str | int, str]`"
79+
# error: [invalid-assignment] "Object of type `tuple[list[Unknown], Literal["foo"]]` is not assignable to `tuple[str | int, str]`"
8080
c: tuple[str | int, str] = ([], "foo")
8181
```
8282

crates/ty_python_semantic/resources/mdtest/attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ reveal_type(False.real) # revealed: Literal[0]
17281728
All attribute access on literal `bytes` types is currently delegated to `builtins.bytes`:
17291729

17301730
```py
1731-
# revealed: bound method Literal[b"foo"].join(iterable_of_bytes: @Todo(specialized non-generic class), /) -> bytes
1731+
# revealed: bound method Literal[b"foo"].join(iterable_of_bytes: Iterable[@Todo(Support for `typing.TypeAlias`)], /) -> bytes
17321732
reveal_type(b"foo".join)
17331733
# revealed: bound method Literal[b"foo"].endswith(suffix: @Todo(Support for `typing.TypeAlias`), start: SupportsIndex | None = ellipsis, end: SupportsIndex | None = ellipsis, /) -> bool
17341734
reveal_type(b"foo".endswith)

crates/ty_python_semantic/resources/mdtest/expression/lambda.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ lambda x=1: reveal_type(x) # revealed: Unknown | Literal[1]
7979
Using a variadic parameter:
8080

8181
```py
82-
# TODO: should be `tuple[Unknown, ...]` (needs generics)
83-
lambda *args: reveal_type(args) # revealed: tuple
82+
lambda *args: reveal_type(args) # revealed: tuple[Unknown, ...]
8483
```
8584

8685
Using a keyword-variadic parameter:

crates/ty_python_semantic/resources/mdtest/function/parameters.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def f(a, b: int, c=1, d: int = 2, /, e=3, f: Literal[4] = 4, *args: object, g=5,
2525
reveal_type(f) # revealed: Literal[4]
2626
reveal_type(g) # revealed: Unknown | Literal[5]
2727
reveal_type(h) # revealed: Literal[6]
28-
# TODO: should be `tuple[object, ...]` (needs generics)
29-
reveal_type(args) # revealed: tuple
28+
# TODO: should be `tuple[object, ...]`
29+
reveal_type(args) # revealed: tuple[Unknown, ...]
3030
reveal_type(kwargs) # revealed: dict[str, str]
3131
```
3232

@@ -36,8 +36,7 @@ def f(a, b: int, c=1, d: int = 2, /, e=3, f: Literal[4] = 4, *args: object, g=5,
3636

3737
```py
3838
def g(*args, **kwargs):
39-
# TODO: should be `tuple[Unknown, ...]` (needs generics)
40-
reveal_type(args) # revealed: tuple
39+
reveal_type(args) # revealed: tuple[Unknown, ...]
4140
reveal_type(kwargs) # revealed: dict[str, Unknown]
4241
```
4342

crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ In a specialized generic alias, the specialization is applied to the attributes
399399
class.
400400

401401
```py
402-
from typing import Generic, TypeVar
402+
from typing import Generic, TypeVar, Protocol
403403

404404
T = TypeVar("T")
405405
U = TypeVar("U")
@@ -425,6 +425,33 @@ reveal_type(c.y) # revealed: str
425425
reveal_type(c.method1()) # revealed: int
426426
reveal_type(c.method2()) # revealed: str
427427
reveal_type(c.method3()) # revealed: LinkedList[int]
428+
429+
class SomeProtocol(Protocol[T]):
430+
x: T
431+
432+
class Foo:
433+
x: int
434+
435+
class D(Generic[T, U]):
436+
x: T
437+
y: U
438+
439+
def method1(self) -> T:
440+
return self.x
441+
442+
def method2(self) -> U:
443+
return self.y
444+
445+
def method3(self) -> SomeProtocol[T]:
446+
return Foo()
447+
448+
d = D[int, str]()
449+
reveal_type(d.x) # revealed: int
450+
reveal_type(d.y) # revealed: str
451+
reveal_type(d.method1()) # revealed: int
452+
reveal_type(d.method2()) # revealed: str
453+
reveal_type(d.method3()) # revealed: SomeProtocol[int]
454+
reveal_type(d.method3().x) # revealed: int
428455
```
429456

430457
## Cyclic class definitions

crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ T = TypeVar("T")
3838
U: TypeVar = TypeVar("U")
3939

4040
# error: [invalid-legacy-type-variable] "A legacy `typing.TypeVar` must be immediately assigned to a variable"
41+
# error: [invalid-type-form] "Function calls are not allowed in type expressions"
4142
TestList = list[TypeVar("W")]
4243
```
4344

crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ from typing import Generic, TypeVar
6565

6666
T = TypeVar("T")
6767

68-
# error: [invalid-generic-class] "Cannot both inherit from `Generic` and use PEP 695 type variables"
68+
# error: [invalid-generic-class] "Cannot both inherit from `typing.Generic` and use PEP 695 type variables"
6969
class BothGenericSyntaxes[U](Generic[T]): ...
7070
```
7171

crates/ty_python_semantic/resources/mdtest/import/dunder_all.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ from subexporter import *
785785

786786
# TODO: Should be `list[str]`
787787
# TODO: Should we avoid including `Unknown` for this case?
788-
reveal_type(__all__) # revealed: Unknown | list
788+
reveal_type(__all__) # revealed: Unknown | list[Unknown]
789789

790790
__all__.append("B")
791791

crates/ty_python_semantic/resources/mdtest/literal/collections/list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
## Empty list
44

55
```py
6-
reveal_type([]) # revealed: list
6+
reveal_type([]) # revealed: list[Unknown]
77
```

crates/ty_python_semantic/resources/mdtest/literal/collections/set.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
## Basic set
44

55
```py
6-
reveal_type({1, 2}) # revealed: set
6+
reveal_type({1, 2}) # revealed: set[Unknown]
77
```

crates/ty_python_semantic/resources/mdtest/named_tuple.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ alice2 = Person2(1, "Alice")
4848
# TODO: should be an error
4949
Person2(1)
5050

51-
reveal_type(alice2.id) # revealed: @Todo(GenericAlias instance)
52-
reveal_type(alice2.name) # revealed: @Todo(GenericAlias instance)
51+
reveal_type(alice2.id) # revealed: @Todo(functional `NamedTuple` syntax)
52+
reveal_type(alice2.name) # revealed: @Todo(functional `NamedTuple` syntax)
5353
```
5454

5555
### Multiple Inheritance

crates/ty_python_semantic/resources/mdtest/narrow/match.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ match x:
133133
case "foo" | 42 | None:
134134
reveal_type(x) # revealed: Literal["foo", 42] | None
135135
case "foo" | tuple():
136-
reveal_type(x) # revealed: tuple
136+
reveal_type(x) # revealed: tuple[Unknown, ...]
137137
case True | False:
138138
reveal_type(x) # revealed: bool
139139
case 3.14 | 2.718 | 1.414:
140-
reveal_type(x) # revealed: float & ~tuple
140+
reveal_type(x) # revealed: float & ~tuple[Unknown, ...]
141141

142142
reveal_type(x) # revealed: object
143143
```
@@ -155,7 +155,7 @@ reveal_type(x) # revealed: object
155155
match x:
156156
case "foo" | 42 | None if reveal_type(x): # revealed: Literal["foo", 42] | None
157157
pass
158-
case "foo" | tuple() if reveal_type(x): # revealed: Literal["foo"] | tuple
158+
case "foo" | tuple() if reveal_type(x): # revealed: Literal["foo"] | tuple[Unknown, ...]
159159
pass
160160
case True | False if reveal_type(x): # revealed: bool
161161
pass

crates/ty_python_semantic/resources/mdtest/protocols.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Bar1(Protocol[T], Generic[T]):
5858
class Bar2[T](Protocol):
5959
x: T
6060

61+
# error: [invalid-generic-class] "Cannot both inherit from subscripted `typing.Protocol` and use PEP 695 type variables"
6162
class Bar3[T](Protocol[T]):
6263
x: T
6364
```
@@ -70,8 +71,8 @@ simultaneously:
7071
class DuplicateBases(Protocol, Protocol[T]):
7172
x: T
7273

73-
# TODO: should not have `Protocol` multiple times
74-
# revealed: tuple[<class 'DuplicateBases'>, typing.Protocol, @Todo(`Protocol[]` subscript), typing.Generic, <class 'object'>]
74+
# TODO: should not have `Protocol` or `Generic` multiple times
75+
# revealed: tuple[<class 'DuplicateBases[Unknown]'>, typing.Protocol, typing.Generic, typing.Protocol[T], typing.Generic[T], <class 'object'>]
7576
reveal_type(DuplicateBases.__mro__)
7677
```
7778

crates/ty_python_semantic/resources/mdtest/scopes/moduletype_attrs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ reveal_type(__loader__) # revealed: LoaderProtocol | None
1313
reveal_type(__package__) # revealed: str | None
1414
reveal_type(__doc__) # revealed: str | None
1515
reveal_type(__spec__) # revealed: ModuleSpec | None
16-
17-
reveal_type(__path__) # revealed: @Todo(specialized non-generic class)
16+
reveal_type(__path__) # revealed: MutableSequence[str]
1817

1918
class X:
2019
reveal_type(__name__) # revealed: str

0 commit comments

Comments
 (0)