| 1 |
[case testOrErrorSyntax] |
| 2 |
from typing import Union |
| 3 |
x : Union[bool, str] |
| 4 |
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | str") |
| 5 |
|
| 6 |
[case testOrNoneErrorSyntax] |
| 7 |
from typing import Union |
| 8 |
x : Union[bool, None] |
| 9 |
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | None") |
| 10 |
|
| 11 |
[case testNoneAsFinalItem] |
| 12 |
from typing import Union |
| 13 |
x : Union[bool, None, str] |
| 14 |
x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | str | None") |
| 15 |
|
| 16 |
[case testLiteralOrErrorSyntax] |
| 17 |
from typing import Literal, Union |
| 18 |
x : Union[Literal[1], Literal[2], str] |
| 19 |
x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1, 2] | str") |
| 20 |
[builtins fixtures/tuple.pyi] |
| 21 |
|
| 22 |
[case testLiteralOrNoneErrorSyntax] |
| 23 |
from typing import Literal, Union |
| 24 |
x : Union[Literal[1], None] |
| 25 |
x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1] | None") |
| 26 |
[builtins fixtures/tuple.pyi] |
| 27 |
|
| 28 |
[case testOrSyntaxRecombined] |
| 29 |
# flags: --allow-redefinition --local-partial-types |
| 30 |
# The following revealed type is recombined because the finally body is visited twice. |
| 31 |
try: |
| 32 |
x = 1 |
| 33 |
x = "" |
| 34 |
x = {1: ""} |
| 35 |
finally: |
| 36 |
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str | builtins.dict[builtins.int, builtins.str]" |
| 37 |
[builtins fixtures/isinstancelist.pyi] |