Skip to content

Commit 33801c0

Browse files
added test_expanded_union_mirrors_isinstance tests
1 parent 0bd69c0 commit 33801c0

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

Lib/test/test_patma.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,51 @@ def test_patma_legacy_union_type(self):
34603460
w = 0
34613461
self.assertIsNone(w)
34623462

3463-
def test_union_mirrors_isinstance_success(self):
3463+
def test_expanded_union_mirrors_isinstance_success(self):
3464+
ListOfInt = list[int]
3465+
t = int | ListOfInt
3466+
try: # get the isinstance result
3467+
reference = isinstance(1, t)
3468+
except TypeError as exc:
3469+
reference = exc
3470+
3471+
try: # get the match-case result
3472+
match 1:
3473+
case int() | ListOfInt():
3474+
result = True
3475+
case _:
3476+
result = False
3477+
except TypeError as exc:
3478+
result = exc
3479+
3480+
# we should ge the same result
3481+
self.assertIs(result, True)
3482+
self.assertIs(reference, True)
3483+
3484+
def test_expanded_union_mirrors_isinstance_failure(self):
3485+
ListOfInt = list[int]
3486+
t = ListOfInt | int
3487+
3488+
try: # get the isinstance result
3489+
reference = isinstance(1, t)
3490+
except TypeError as exc:
3491+
reference = exc
3492+
3493+
try: # get the match-case result
3494+
match 1:
3495+
case ListOfInt() | int():
3496+
result = True
3497+
case _:
3498+
result = False
3499+
except TypeError as exc:
3500+
result = exc
3501+
3502+
# we should ge the same result
3503+
self.assertIsInstance(result, TypeError)
3504+
self.assertIsInstance(reference, TypeError)
3505+
3506+
3507+
def test_union_type_mirrors_isinstance_success(self):
34643508
t = int | list[int]
34653509

34663510
try: # get the isinstance result
@@ -3481,7 +3525,7 @@ def test_union_mirrors_isinstance_success(self):
34813525
self.assertIs(result, True)
34823526
self.assertIs(reference, True)
34833527

3484-
def test_union_mirrors_isinstance_failure(self):
3528+
def test_union_type_mirrors_isinstance_failure(self):
34853529
t = list[int] | int
34863530

34873531
try: # get the isinstance result

0 commit comments

Comments
 (0)