|
| 1 | +[case testUnionErrorSyntax] |
| 2 | +# flags: --python-version 3.10 --no-force-union-syntax |
| 3 | +from typing import Union |
| 4 | +x : Union[bool, str] |
| 5 | +x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | str") |
| 6 | + |
| 7 | +[case testOrErrorSyntax] |
| 8 | +# flags: --python-version 3.10 --force-union-syntax |
| 9 | +from typing import Union |
| 10 | +x : Union[bool, str] |
| 11 | +x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "Union[bool, str]") |
| 12 | + |
| 13 | +[case testOrNoneErrorSyntax] |
| 14 | +# flags: --python-version 3.10 --no-force-union-syntax |
| 15 | +from typing import Union |
| 16 | +x : Union[bool, None] |
| 17 | +x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | None") |
| 18 | + |
| 19 | +[case testOptionalErrorSyntax] |
| 20 | +# flags: --python-version 3.10 --force-union-syntax |
| 21 | +from typing import Union |
| 22 | +x : Union[bool, None] |
| 23 | +x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[bool]") |
| 24 | + |
| 25 | +[case testNoneAsFinalItem] |
| 26 | +# flags: --python-version 3.10 --no-force-union-syntax |
| 27 | +from typing import Union |
| 28 | +x : Union[bool, None, str] |
| 29 | +x = 3 # E: Incompatible types in assignment (expression has type "int", variable has type "bool | str | None") |
| 30 | + |
| 31 | +[case testLiteralOrErrorSyntax] |
| 32 | +# flags: --python-version 3.10 --no-force-union-syntax |
| 33 | +from typing import Union |
| 34 | +from typing_extensions import Literal |
| 35 | +x : Union[Literal[1], Literal[2], str] |
| 36 | +x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1, 2] | str") |
| 37 | +[builtins fixtures/tuple.pyi] |
| 38 | + |
| 39 | +[case testLiteralUnionErrorSyntax] |
| 40 | +# flags: --python-version 3.10 --force-union-syntax |
| 41 | +from typing import Union |
| 42 | +from typing_extensions import Literal |
| 43 | +x : Union[Literal[1], Literal[2], str] |
| 44 | +x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Union[str, Literal[1, 2]]") |
| 45 | +[builtins fixtures/tuple.pyi] |
| 46 | + |
| 47 | +[case testLiteralOrNoneErrorSyntax] |
| 48 | +# flags: --python-version 3.10 --no-force-union-syntax |
| 49 | +from typing import Union |
| 50 | +from typing_extensions import Literal |
| 51 | +x : Union[Literal[1], None] |
| 52 | +x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Literal[1] | None") |
| 53 | +[builtins fixtures/tuple.pyi] |
| 54 | + |
| 55 | +[case testLiteralOptionalErrorSyntax] |
| 56 | +# flags: --python-version 3.10 --force-union-syntax |
| 57 | +from typing import Union |
| 58 | +from typing_extensions import Literal |
| 59 | +x : Union[Literal[1], None] |
| 60 | +x = 3 # E: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Optional[Literal[1]]") |
| 61 | +[builtins fixtures/tuple.pyi] |
0 commit comments