-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathcheck-union-error-syntax.test
More file actions
37 lines (32 loc) · 1.39 KB
/
check-union-error-syntax.test
File metadata and controls
37 lines (32 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[case testOrErrorSyntax]
from typing import Union
x : Union[bool, str]
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | str")
[case testOrNoneErrorSyntax]
from typing import Union
x : Union[bool, None]
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | None")
[case testNoneAsFinalItem]
from typing import Union
x : Union[bool, None, str]
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | str | None")
[case testLiteralOrErrorSyntax]
from typing import Literal, Union
x : Union[Literal[1], Literal[2], str]
x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1, 2] | str")
[builtins fixtures/tuple.pyi]
[case testLiteralOrNoneErrorSyntax]
from typing import Literal, Union
x : Union[Literal[1], None]
x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1] | None")
[builtins fixtures/tuple.pyi]
[case testOrSyntaxRecombined]
# flags: --allow-redefinition --local-partial-types
# The following revealed type is recombined because the finally body is visited twice.
try:
x = 1
x = ""
x = {1: ""}
finally:
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str | builtins.dict[builtins.int, builtins.str]"
[builtins fixtures/isinstancelist.pyi]