Skip to content

Commit 4c1bd69

Browse files
committed
Fixes to tests for type errors and incorrect expectations.
1 parent f124c33 commit 4c1bd69

File tree

8 files changed

+28
-17
lines changed

8 files changed

+28
-17
lines changed

conformance/tests/enums_members.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Pet(Enum): # E?: Uninitialized attributes (pyre)
1616
genus: str # Non-member attribute
1717
species: str # Non-member attribute
1818

19-
CAT = 1 # Member attribute
20-
DOG = 2 # Member attribute
19+
CAT = "felis", "catus" # Member attribute
20+
DOG = "canis", "lupus" # Member attribute
2121

2222
def __init__(self, genus: str, species: str) -> None:
2323
self.genus = genus

conformance/tests/generics_defaults.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class Class_TypeVarTuple(Generic[*DefaultTs]): ...
127127
def func1(x: int | set[T4]) -> T4: ...
128128

129129

130-
assert_type(func1(0), int)
130+
assert_type(func1(0), int) # E[optional-default-use]
131+
assert_type(func1(0), Any) # E[optional-default-use]
131132

132133

133134
# > A ``TypeVar`` that immediately follows a ``TypeVarTuple`` is not allowed
@@ -167,4 +168,4 @@ def meth(self, /) -> Self:
167168

168169

169170
assert_type(Foo7.meth, Callable[[Foo7[int]], Foo7[int]])
170-
assert_type(Foo7.attr, int)
171+
assert_type(Foo7().attr, int)

conformance/tests/generics_self_advanced.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def method2(self) -> None:
3939

4040
@classmethod
4141
def method3(cls) -> None:
42+
a = cls.a # E?: zuban errors on accessing `Self` in a classmethod
43+
a_elem = cls.a[0] # E?: zuban errors on accessing `Self` in a classmethod
4244
assert_type(cls, type[Self])
43-
assert_type(cls.a, list[Self])
44-
assert_type(cls.a[0], Self)
45+
assert_type(a, list[Self])
46+
assert_type(a_elem, Self)
4547
assert_type(cls.method1(), Self)

conformance/tests/generics_syntax_infer_variance.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Specification: https://peps.python.org/pep-0695/#auto-variance-for-typevar
66

7-
from typing import Final, Generic, Iterator, Sequence, TypeVar
7+
from typing import Final, Generic, Iterator, overload, Sequence, TypeVar
88
from dataclasses import dataclass
99

1010

@@ -30,7 +30,17 @@ def __iter__(self) -> Iterator[T]:
3030

3131

3232
class ShouldBeCovariant2(Sequence[T]):
33-
pass
33+
@overload
34+
def __getitem__(self, index: int) -> T:
35+
...
36+
@overload
37+
def __getitem__(self, index: slice) -> Sequence[T]:
38+
...
39+
def __getitem__(self, index: int | slice) -> T | Sequence[T]:
40+
...
41+
42+
def __len__(self) -> int:
43+
...
3444

3545

3646
vco2_1: ShouldBeCovariant2[float] = ShouldBeCovariant2[int]() # OK

conformance/tests/generics_type_erasure.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Specification: https://typing.readthedocs.io/en/latest/spec/generics.html#instantiating-generic-classes-and-type-erasure
22

3-
from typing import Any, TypeVar, Generic, assert_type
3+
from typing import Any, Never, TypeVar, Generic, assert_type
44

55
T = TypeVar("T")
66

@@ -16,10 +16,12 @@ def __init__(self, label: T | None = None) -> None:
1616

1717
assert_type(Node(''), Node[str])
1818
assert_type(Node(0), Node[int])
19-
assert_type(Node(), Node[Any])
19+
assert_type(Node(), Node[Any]) # E[any-or-never1]
20+
assert_type(Node(), Node[Never]) # E[any-or-never1]
2021

2122
assert_type(Node(0).label, int)
22-
assert_type(Node().label, Any)
23+
assert_type(Node().label, Any) # E[any-or-never2]
24+
assert_type(Node().label, Never) # E[any-or-never2]
2325

2426
# > In case the inferred type uses [Any] but the intended type is more specific,
2527
# > you can use an annotation to force the type of the variable, e.g.:

conformance/tests/overloads_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Child(Base): # E[override-final]
173173
# questions of override LSP compatibility and focus only on the override):
174174

175175
@overload # E[override-final]
176-
def final_method(self, x: int) -> int: ...
176+
def final_method(self, x: int) -> int: ... # E[override-final]
177177

178178
@overload
179179
def final_method(self, x: str) -> str: ...

conformance/tests/protocols_explicit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class Proto3(Proto2, Protocol):
8282

8383
class Concrete1(Proto1):
8484
def __init__(self):
85-
self.cm1 = 1
8685
self.im1 = 1
8786
self.im3 = 3
8887

@@ -107,7 +106,7 @@ def __init__(self):
107106
self.cm11 = 11
108107

109108

110-
c3 = Concrete3() # E: cannot instantiate abstract class
109+
c3 = Concrete3()
111110

112111

113112
class Concrete4(Proto1, Proto3):

conformance/tests/typeddicts_required.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
class NotTypedDict:
1212
x: Required[int] # E: Required not allowed in this context
1313

14-
def __init__(self, x: int) -> None:
15-
self.x = x
16-
1714

1815
def func1(
1916
x: NotRequired[int], # E: NotRequired not allowed in this context

0 commit comments

Comments
 (0)