Skip to content

Commit 61310ad

Browse files
committed
Update test cases
1 parent 7a6a376 commit 61310ad

File tree

71 files changed

+1566
-1566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1566
-1566
lines changed

test-data/unit/check-annotated.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
88
from typing import Union
99
from typing_extensions import Annotated
1010
x: Annotated[Union[int, str], ...]
11-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
11+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
1212
[builtins fixtures/tuple.pyi]
1313

1414
[case testAnnotated2]
@@ -51,7 +51,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
5151
from typing import Union
5252
from typing_extensions import Annotated
5353
x: Annotated[Annotated[Union[int, str], ...], ...]
54-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
54+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
5555
[builtins fixtures/tuple.pyi]
5656

5757
[case testAnnotatedNestedBadType]
@@ -114,7 +114,7 @@ from typing_extensions import Annotated
114114
T = TypeVar('T')
115115
Alias = Annotated[Union[T, str], ...]
116116
x: Alias[int]
117-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
117+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
118118
[builtins fixtures/tuple.pyi]
119119

120120
[case testAnnotatedSecondParamNonType]

test-data/unit/check-async-await.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async def f() -> None:
205205
pass
206206

207207
async for z in C(): # type: Union[int, str]
208-
reveal_type(z) # N: Revealed type is "Union[builtins.int, builtins.str]"
208+
reveal_type(z) # N: Revealed type is "builtins.int | builtins.str"
209209
[builtins fixtures/async_await.pyi]
210210
[typing fixtures/typing-async.pyi]
211211

@@ -952,7 +952,7 @@ async def foo(x: B) -> A: ...
952952
async def foo(x): ...
953953

954954
async def bar(x: Union[A, B]) -> None:
955-
reveal_type(await foo(x)) # N: Revealed type is "Union[__main__.B, __main__.A]"
955+
reveal_type(await foo(x)) # N: Revealed type is "__main__.B | __main__.A"
956956

957957
[builtins fixtures/async_await.pyi]
958958
[typing fixtures/typing-async.pyi]

test-data/unit/check-basic.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ reveal_type(__file__) # N: Revealed type is "builtins.str"
220220
reveal_type(__package__) # N: Revealed type is "builtins.str"
221221
reveal_type(__annotations__) # N: Revealed type is "builtins.dict[builtins.str, Any]"
222222
# This will actually reveal Union[importlib.machinery.ModuleSpec, None]
223-
reveal_type(__spec__) # N: Revealed type is "Union[builtins.object, None]"
223+
reveal_type(__spec__) # N: Revealed type is "builtins.object | None"
224224

225225
import module
226226
reveal_type(module.__name__) # N: Revealed type is "builtins.str"
@@ -416,18 +416,18 @@ D = TypedDict('D', {'y': int})
416416

417417
def foo() -> Optional[A]:
418418
b = True
419-
return a.A() if b else None # E: Incompatible return value type (got "Optional[a.A]", expected "Optional[b.A]")
419+
return a.A() if b else None # E: Incompatible return value type (got "a.A | None", expected "b.A | None")
420420

421421
def bar() -> List[A]:
422422
l = [a.A()]
423423
return l # E: Incompatible return value type (got "list[a.A]", expected "list[b.A]")
424424

425425
def baz() -> Union[A, int]:
426426
b = True
427-
return a.A() if b else 10 # E: Incompatible return value type (got "Union[a.A, int]", expected "Union[b.A, int]")
427+
return a.A() if b else 10 # E: Incompatible return value type (got "a.A | int", expected "b.A | int")
428428

429429
def spam() -> Optional[A]:
430-
return a.A() # E: Incompatible return value type (got "a.A", expected "Optional[b.A]")
430+
return a.A() # E: Incompatible return value type (got "a.A", expected "b.A | None")
431431

432432
def eggs() -> Sequence[A]:
433433
x = [a.A()]
@@ -516,11 +516,11 @@ x: """
516516
str
517517

518518
"""
519-
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
519+
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str"
520520

521521
y: """(
522522
int |
523523
str
524524
)
525525
"""
526-
reveal_type(y) # N: Revealed type is "Union[builtins.int, builtins.str]"
526+
reveal_type(y) # N: Revealed type is "builtins.int | builtins.str"

test-data/unit/check-callable.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ x = 5 # type: Union[int, Callable[[], str], Callable[[], int]]
4747

4848
if callable(x):
4949
y = x() + 2 # E: Unsupported operand types for + ("str" and "int") \
50-
# N: Left operand is of type "Union[str, int]"
50+
# N: Left operand is of type "str | int"
5151
else:
5252
z = x + 6
5353

@@ -62,7 +62,7 @@ if callable(x):
6262
y = x() + 'test'
6363
else:
6464
z = x + 6 # E: Unsupported operand types for + ("str" and "int") \
65-
# N: Left operand is of type "Union[int, str]"
65+
# N: Left operand is of type "int | str"
6666

6767
[builtins fixtures/callable.pyi]
6868

@@ -156,7 +156,7 @@ if callable(x) and x() == 'test':
156156
x()
157157
else:
158158
x + 5 # E: Unsupported left operand type for + ("Callable[[], str]") \
159-
# N: Left operand is of type "Union[int, Callable[[], str]]"
159+
# N: Left operand is of type "int | Callable[[], str]"
160160

161161
[builtins fixtures/callable.pyi]
162162

@@ -280,9 +280,9 @@ T = Union[Union[int, Callable[[], int]], Union[str, Callable[[], str]]]
280280

281281
def f(t: T) -> None:
282282
if callable(t):
283-
reveal_type(t()) # N: Revealed type is "Union[builtins.int, builtins.str]"
283+
reveal_type(t()) # N: Revealed type is "builtins.int | builtins.str"
284284
else:
285-
reveal_type(t) # N: Revealed type is "Union[builtins.int, builtins.str]"
285+
reveal_type(t) # N: Revealed type is "builtins.int | builtins.str"
286286

287287
[builtins fixtures/callable.pyi]
288288

test-data/unit/check-class-namedtuple.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class HasNone(NamedTuple):
396396
x: int
397397
y: Optional[int] = None
398398

399-
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
399+
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, builtins.int | None, fallback=__main__.HasNone]"
400400

401401
class Parameterized(NamedTuple):
402402
x: int
@@ -425,7 +425,7 @@ class HasNone(NamedTuple):
425425
x: int
426426
y: Optional[int] = None
427427

428-
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, Union[builtins.int, None], fallback=__main__.HasNone]"
428+
reveal_type(HasNone(1)) # N: Revealed type is "tuple[builtins.int, builtins.int | None, fallback=__main__.HasNone]"
429429
HasNone(None) # E: Argument 1 to "HasNone" has incompatible type "None"; expected "int"
430430
HasNone(1, y=None)
431431
HasNone(1, y=2)

test-data/unit/check-classes.test

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ class A:
769769

770770
class B(A):
771771
def __replace__(self, x: str) -> Self: pass # E: \
772-
# E: Argument 1 of "__replace__" is incompatible with supertype "A"; supertype defines the argument type as "Optional[str]" [override] \
772+
# E: Argument 1 of "__replace__" is incompatible with supertype "A"; supertype defines the argument type as "str | None" [override] \
773773
# N: This violates the Liskov substitution principle \
774774
# N: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
775775
[builtins fixtures/tuple.pyi]
@@ -899,18 +899,18 @@ class A:
899899
f4: Union[Callable[[str], str], str]
900900

901901
class B(A):
902-
def f1(self, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]")
902+
def f1(self, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], str] | str", override has type "Callable[[str], str]")
903903
pass
904904

905-
def f2(self, x: object) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[object], str]")
905+
def f2(self, x: object) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], str] | str", override has type "Callable[[object], str]")
906906
pass
907907

908908
@classmethod
909-
def f3(cls, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]")
909+
def f3(cls, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], str] | str", override has type "Callable[[str], str]")
910910
pass
911911

912912
@staticmethod
913-
def f4(x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]")
913+
def f4(x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], str] | str", override has type "Callable[[str], str]")
914914
pass
915915
[builtins fixtures/classmethod.pyi]
916916

@@ -1149,10 +1149,10 @@ T = TypeVar('T')
11491149
def join(x: T, y: T) -> T: pass
11501150

11511151
f1 = join(func, WithMetaclass)
1152-
reveal_type(f1()) # N: Revealed type is "Union[__main__.WithMetaclass, None]"
1152+
reveal_type(f1()) # N: Revealed type is "__main__.WithMetaclass | None"
11531153

11541154
f2 = join(WithMetaclass, func)
1155-
reveal_type(f2()) # N: Revealed type is "Union[__main__.WithMetaclass, None]"
1155+
reveal_type(f2()) # N: Revealed type is "__main__.WithMetaclass | None"
11561156

11571157
-- Attribute access in class body
11581158
-- ------------------------------
@@ -2829,9 +2829,9 @@ a: Union[int, float]
28292829
b: int
28302830
c: float
28312831

2832-
reveal_type(a + a) # N: Revealed type is "Union[builtins.int, builtins.float]"
2833-
reveal_type(a + b) # N: Revealed type is "Union[builtins.int, builtins.float]"
2834-
reveal_type(b + a) # N: Revealed type is "Union[builtins.int, builtins.float]"
2832+
reveal_type(a + a) # N: Revealed type is "builtins.int | builtins.float"
2833+
reveal_type(a + b) # N: Revealed type is "builtins.int | builtins.float"
2834+
reveal_type(b + a) # N: Revealed type is "builtins.int | builtins.float"
28352835
reveal_type(a + c) # N: Revealed type is "builtins.float"
28362836
reveal_type(c + a) # N: Revealed type is "builtins.float"
28372837
[builtins fixtures/ops.pyi]
@@ -2877,16 +2877,16 @@ a + a # E: Unsupported operand types for + ("Foo" and "Bar") \
28772877
# N: Both left and right operands are unions
28782878

28792879
a + b # E: Unsupported operand types for + ("Bar" and "Foo") \
2880-
# N: Left operand is of type "Union[Foo, Bar]"
2880+
# N: Left operand is of type "Foo | Bar"
28812881

28822882
b + a # E: Unsupported operand types for + ("Foo" and "Bar") \
2883-
# N: Right operand is of type "Union[Foo, Bar]"
2883+
# N: Right operand is of type "Foo | Bar"
28842884

28852885
a + c # E: Unsupported operand types for + ("Foo" and "Bar") \
2886-
# N: Left operand is of type "Union[Foo, Bar]"
2886+
# N: Left operand is of type "Foo | Bar"
28872887

28882888
c + a # E: Unsupported operand types for + ("Bar" and "Foo") \
2889-
# N: Right operand is of type "Union[Foo, Bar]"
2889+
# N: Right operand is of type "Foo | Bar"
28902890

28912891
[case testOperatorDoubleUnionNoRelationship2]
28922892
from typing import Union
@@ -2903,9 +2903,9 @@ a: Union[Foo, Bar]
29032903
b: Foo
29042904
c: Bar
29052905

2906-
reveal_type(a + a) # N: Revealed type is "Union[__main__.Foo, __main__.Bar]"
2907-
reveal_type(a + b) # N: Revealed type is "Union[__main__.Foo, __main__.Bar]"
2908-
reveal_type(b + a) # N: Revealed type is "Union[__main__.Foo, __main__.Bar]"
2906+
reveal_type(a + a) # N: Revealed type is "__main__.Foo | __main__.Bar"
2907+
reveal_type(a + b) # N: Revealed type is "__main__.Foo | __main__.Bar"
2908+
reveal_type(b + a) # N: Revealed type is "__main__.Foo | __main__.Bar"
29092909
reveal_type(a + c) # N: Revealed type is "__main__.Bar"
29102910
reveal_type(c + a) # N: Revealed type is "__main__.Bar"
29112911

@@ -2946,11 +2946,11 @@ class D:
29462946
x: Union[A, B]
29472947
y: Union[C, D]
29482948

2949-
reveal_type(x + y) # N: Revealed type is "Union[__main__.Out3, __main__.Out1, __main__.Out2, __main__.Out4]"
2950-
reveal_type(A() + y) # N: Revealed type is "Union[__main__.Out3, __main__.Out1]"
2951-
reveal_type(B() + y) # N: Revealed type is "Union[__main__.Out2, __main__.Out4]"
2952-
reveal_type(x + C()) # N: Revealed type is "Union[__main__.Out3, __main__.Out2]"
2953-
reveal_type(x + D()) # N: Revealed type is "Union[__main__.Out1, __main__.Out4]"
2949+
reveal_type(x + y) # N: Revealed type is "__main__.Out3 | __main__.Out1 | __main__.Out2 | __main__.Out4"
2950+
reveal_type(A() + y) # N: Revealed type is "__main__.Out3 | __main__.Out1"
2951+
reveal_type(B() + y) # N: Revealed type is "__main__.Out2 | __main__.Out4"
2952+
reveal_type(x + C()) # N: Revealed type is "__main__.Out3 | __main__.Out2"
2953+
reveal_type(x + D()) # N: Revealed type is "__main__.Out1 | __main__.Out4"
29542954

29552955
[case testOperatorDoubleUnionDivision]
29562956
from typing import Union
@@ -2970,8 +2970,8 @@ def sum(x: Iterable[T]) -> Union[T, int]: ...
29702970
def len(x: Iterable[T]) -> int: ...
29712971

29722972
x = [1.1, 2.2, 3.3]
2973-
reveal_type(sum(x)) # N: Revealed type is "Union[builtins.float, builtins.int]"
2974-
reveal_type(sum(x) / len(x)) # N: Revealed type is "Union[builtins.float, builtins.int]"
2973+
reveal_type(sum(x)) # N: Revealed type is "builtins.float | builtins.int"
2974+
reveal_type(sum(x) / len(x)) # N: Revealed type is "builtins.float | builtins.int"
29752975
[builtins fixtures/floatdict.pyi]
29762976

29772977
[case testOperatorWithEmptyListAndSum]
@@ -3423,7 +3423,7 @@ class C:
34233423

34243424
x = C(foo=12)
34253425
x.a # E: "C" has no attribute "a"
3426-
C(foo='') # E: Argument "foo" to "C" has incompatible type "str"; expected "Optional[int]"
3426+
C(foo='') # E: Argument "foo" to "C" has incompatible type "str"; expected "int | None"
34273427
[builtins fixtures/__new__.pyi]
34283428

34293429
[case testConstructInstanceWithDynamicallyTyped__new__]
@@ -3850,7 +3850,7 @@ def process(cls: Type[Union[BasicUser, ProUser]]):
38503850
obj = cls()
38513851
cls.bar(obj)
38523852
cls.mro() # Defined in class type
3853-
cls.error # E: Item "type" of "Union[type[BasicUser], type[ProUser]]" has no attribute "error"
3853+
cls.error # E: Item "type" of "type[BasicUser] | type[ProUser]" has no attribute "error"
38543854
[builtins fixtures/classmethod.pyi]
38553855
[out]
38563856

@@ -5608,7 +5608,7 @@ class Bar(NamedTuple):
56085608

56095609
def foo(node: Node) -> int:
56105610
x = node
5611-
reveal_type(node) # N: Revealed type is "Union[tuple[builtins.int, fallback=__main__.Foo], tuple[builtins.int, fallback=__main__.Bar]]"
5611+
reveal_type(node) # N: Revealed type is "tuple[builtins.int, fallback=__main__.Foo] | tuple[builtins.int, fallback=__main__.Bar]"
56125612
return x.x
56135613
[builtins fixtures/tuple.pyi]
56145614
[out]
@@ -5686,7 +5686,7 @@ ForwardUnion = Union['TP', int]
56865686
class TP(NamedTuple('TP', [('x', int)])): pass
56875687

56885688
def f(x: ForwardUnion) -> None:
5689-
reveal_type(x) # N: Revealed type is "Union[tuple[builtins.int, fallback=__main__.TP], builtins.int]"
5689+
reveal_type(x) # N: Revealed type is "tuple[builtins.int, fallback=__main__.TP] | builtins.int"
56905690
if isinstance(x, TP):
56915691
reveal_type(x) # N: Revealed type is "tuple[builtins.int, fallback=__main__.TP]"
56925692
[builtins fixtures/isinstance.pyi]
@@ -7147,7 +7147,7 @@ def test() -> None:
71477147
x = Other
71487148
else:
71497149
return
7150-
reveal_type(x) # N: Revealed type is "Union[def () -> __main__.One, def () -> __main__.Other]"
7150+
reveal_type(x) # N: Revealed type is "def () -> __main__.One | def () -> __main__.Other"
71517151
reveal_type(x.x) # N: Revealed type is "builtins.int"
71527152
[builtins fixtures/isinstancelist.pyi]
71537153

@@ -7362,10 +7362,10 @@ from typing import Tuple, Optional
73627362
# Check for some cases that aren't allowed
73637363

73647364
class X:
7365-
def __new__(cls) -> Optional[Y]: # E: "__new__" must return a class instance (got "Optional[Y]")
7365+
def __new__(cls) -> Optional[Y]: # E: "__new__" must return a class instance (got "Y | None")
73667366
pass
73677367
class Y:
7368-
def __new__(cls) -> Optional[int]: # E: "__new__" must return a class instance (got "Optional[int]")
7368+
def __new__(cls) -> Optional[int]: # E: "__new__" must return a class instance (got "int | None")
73697369
pass
73707370

73717371

@@ -7807,7 +7807,7 @@ class Foo:
78077807
self.x = None
78087808
self.y = []
78097809

7810-
reveal_type(Foo().x) # N: Revealed type is "Union[Any, None]"
7810+
reveal_type(Foo().x) # N: Revealed type is "Any | None"
78117811
reveal_type(Foo().y) # N: Revealed type is "builtins.list[Any]"
78127812
[builtins fixtures/list.pyi]
78137813

test-data/unit/check-classvar.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ A.x = 'a'
165165
A.x = B()
166166
reveal_type(A().x)
167167
[out]
168-
main:8: error: Incompatible types in assignment (expression has type "B", variable has type "Union[int, str]")
169-
main:9: note: Revealed type is "Union[builtins.int, builtins.str]"
168+
main:8: error: Incompatible types in assignment (expression has type "B", variable has type "int | str")
169+
main:9: note: Revealed type is "builtins.int | builtins.str"
170170

171171
[case testOverrideWithNarrowedUnion]
172172
from typing import ClassVar, Union
@@ -188,7 +188,7 @@ class D:
188188
class E(D):
189189
x = None # type: ClassVar[Union[A, B, C]]
190190
[out]
191-
main:8: error: Incompatible types in assignment (expression has type "Union[A, B, C]", base class "D" defined the type as "Union[A, B]")
191+
main:8: error: Incompatible types in assignment (expression has type "A | B | C", base class "D" defined the type as "A | B")
192192

193193
[case testAssignmentToCallableRet]
194194
from typing import ClassVar
@@ -320,8 +320,8 @@ A[int, str].x # E: Access to generic class variables is ambiguous
320320
class Bad(A[int, str]):
321321
pass
322322
reveal_type(Bad.x) # E: Access to generic class variables is ambiguous \
323-
# N: Revealed type is "Union[builtins.int, tuple[builtins.str, type[builtins.str]]]"
324-
reveal_type(Bad().x) # N: Revealed type is "Union[builtins.int, tuple[builtins.str, type[builtins.str]]]"
323+
# N: Revealed type is "builtins.int | tuple[builtins.str, type[builtins.str]]"
324+
reveal_type(Bad().x) # N: Revealed type is "builtins.int | tuple[builtins.str, type[builtins.str]]"
325325

326326
class Good(A[int, str]):
327327
x = 42
@@ -344,7 +344,7 @@ class C:
344344
def f(self) -> int: ...
345345
g: ClassVar[Union[Callable[[C], int], int]] = f
346346

347-
reveal_type(C().g) # N: Revealed type is "Union[def () -> builtins.int, builtins.int]"
347+
reveal_type(C().g) # N: Revealed type is "def () -> builtins.int | builtins.int"
348348

349349
[case testGenericSubclassAccessNoLeak]
350350
from typing import ClassVar, Generic, TypeVar

0 commit comments

Comments
 (0)