@@ -445,28 +445,29 @@ foo([f]) # E: List item 0 has incompatible type "Callable[[], int]"; expected "
445445
446446[case testInferEqualsNotOptional]
447447from typing import Optional
448- x = '' # type: Optional[str]
449- if x == '<string>':
450- reveal_type(x) # N: Revealed type is "builtins.str"
451- else:
452- reveal_type(x) # N: Revealed type is "builtins.str | None"
453- if x is '<string>':
454- reveal_type(x) # N: Revealed type is "builtins.str"
455- else:
456- reveal_type(x) # N: Revealed type is "builtins.str | None"
448+
449+ def main(x: Optional[str]):
450+ if x == '<string>':
451+ reveal_type(x) # N: Revealed type is "builtins.str"
452+ else:
453+ reveal_type(x) # N: Revealed type is "builtins.str | None"
454+ if x is '<string>':
455+ reveal_type(x) # N: Revealed type is "Literal['<string>']"
456+ else:
457+ reveal_type(x) # N: Revealed type is "builtins.str | None"
457458[builtins fixtures/ops.pyi]
458459
459460[case testInferEqualsNotOptionalWithUnion]
460461from typing import Union
461- x = '' # type : Union[str, int, None]
462- if x == '<string>':
463- reveal_type(x) # N: Revealed type is "builtins.str | builtins.int "
464- else:
465- reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
466- if x is '<string>':
467- reveal_type(x) # N: Revealed type is "builtins.str | builtins.int "
468- else:
469- reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
462+ def main(x : Union[str, int, None]):
463+ if x == '<string>':
464+ reveal_type(x) # N: Revealed type is "builtins.str"
465+ else:
466+ reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
467+ if x is '<string>':
468+ reveal_type(x) # N: Revealed type is "Literal['<string>'] "
469+ else:
470+ reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
470471[builtins fixtures/ops.pyi]
471472
472473[case testInferEqualsNotOptionalWithOverlap]
@@ -483,28 +484,30 @@ else:
483484[builtins fixtures/ops.pyi]
484485
485486[case testInferEqualsStillOptionalWithNoOverlap]
487+ # flags: --warn-unreachable
486488from typing import Optional
487- x = '' # type: Optional[str]
488- if x == 0:
489- reveal_type(x) # N: Revealed type is "builtins.str | None"
490- else:
491- reveal_type(x) # N: Revealed type is "builtins.str | None"
492- if x is 0:
493- reveal_type(x) # N: Revealed type is "builtins.str | None"
494- else:
495- reveal_type(x) # N: Revealed type is "builtins.str | None"
489+
490+ def main(x: Optional[str]):
491+ if x == 0:
492+ reveal_type(x) # E: Statement is unreachable
493+ else:
494+ reveal_type(x) # N: Revealed type is "builtins.str | None"
495+ if x is 0:
496+ reveal_type(x) # N: Revealed type is "builtins.str | None"
497+ else:
498+ reveal_type(x) # N: Revealed type is "builtins.str | None"
496499[builtins fixtures/ops.pyi]
497500
498501[case testInferEqualsStillOptionalWithBothOptional]
499502from typing import Union
500503x = '' # type: Union[str, int, None]
501504y = '' # type: Union[str, None]
502505if x == y:
503- reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
506+ reveal_type(x) # N: Revealed type is "builtins.str | None"
504507else:
505508 reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
506509if x is y:
507- reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
510+ reveal_type(x) # N: Revealed type is "builtins.str | None"
508511else:
509512 reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
510513[builtins fixtures/ops.pyi]
0 commit comments