Skip to content

Commit 94c5be7

Browse files
committed
improve test
1 parent ca5120d commit 94c5be7

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

test-data/unit/check-optional.test

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,19 @@ def main(x: Union[str, int, None]):
472472

473473
[case testInferEqualsNotOptionalWithOverlap]
474474
from typing import Union
475-
x = '' # type: Union[str, int, None]
476-
if x == object():
477-
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
478-
else:
479-
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
480-
if x is object():
481-
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
482-
else:
483-
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
475+
476+
def make_random_object() -> object:
477+
return None
478+
479+
def main(x: Union[str, int, None]):
480+
if x == make_random_object():
481+
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
482+
else:
483+
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
484+
if x is make_random_object():
485+
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
486+
else:
487+
reveal_type(x) # N: Revealed type is "builtins.str | builtins.int | None"
484488
[builtins fixtures/ops.pyi]
485489

486490
[case testInferEqualsStillOptionalWithNoOverlap]
@@ -524,14 +528,17 @@ def main(x: Optional[int], y: Optional[int]):
524528
reveal_type(y) # N: Revealed type is "builtins.int | None"
525529

526530
class A: pass
527-
a: Optional[A]
528-
b: Optional[A]
529-
if a == b == object():
530-
reveal_type(a) # N: Revealed type is "__main__.A | None"
531-
reveal_type(b) # N: Revealed type is "__main__.A | None"
532-
else:
533-
reveal_type(a) # N: Revealed type is "__main__.A | None"
534-
reveal_type(b) # N: Revealed type is "__main__.A | None"
531+
532+
def returns_random_object() -> object:
533+
return None
534+
535+
def main2(a: Optional[A], b: Optional[A]):
536+
if a == b == returns_random_object():
537+
reveal_type(a) # N: Revealed type is "__main__.A | None"
538+
reveal_type(b) # N: Revealed type is "__main__.A | None"
539+
else:
540+
reveal_type(a) # N: Revealed type is "__main__.A | None"
541+
reveal_type(b) # N: Revealed type is "__main__.A | None"
535542
[builtins fixtures/ops.pyi]
536543

537544
[case testInferInWithErasedTypes]

0 commit comments

Comments
 (0)