File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -3469,6 +3469,48 @@ def test_patma_legacy_union_type(self):
34693469 w = 0
34703470 self .assertIsNone (w )
34713471
3472+ def test_union_mirrors_isinstance_success (self ):
3473+ t = int | list [int ]
3474+
3475+ try : # get the isinstance result
3476+ reference = isinstance (1 , t )
3477+ except TypeError as exc :
3478+ reference = exc
3479+
3480+ try : # get the match-case result
3481+ match 1 :
3482+ case t ():
3483+ result = True
3484+ case _:
3485+ result = False
3486+ except TypeError as exc :
3487+ result = exc
3488+
3489+ # we should ge the same result
3490+ self .assertIs (result , True )
3491+ self .assertIs (reference , True )
3492+
3493+ def test_union_mirrors_isinstance_failure (self ):
3494+ t = list [int ] | int
3495+
3496+ try : # get the isinstance result
3497+ reference = isinstance (1 , t )
3498+ except TypeError as exc :
3499+ reference = exc
3500+
3501+ try : # get the match-case result
3502+ match 1 :
3503+ case t ():
3504+ result = True
3505+ case _:
3506+ result = False
3507+ except TypeError as exc :
3508+ result = exc
3509+
3510+ # we should ge the same result
3511+ self .assertIsInstance (result , TypeError )
3512+ self .assertIsInstance (reference , TypeError )
3513+
34723514 def test_generic_union_type (self ):
34733515 from collections .abc import Sequence , Set
34743516 t = Sequence [str ] | Set [str ]
You can’t perform that action at this time.
0 commit comments