@@ -776,31 +776,32 @@ def test_union_parameter_chaining(self):
776776 self .assertEqual ((list [T ] | list [S ])[int , int ], list [int ])
777777
778778 def test_union_parameter_substitution (self ):
779- def eq (actual , expected ):
779+ def eq (actual , expected , typed = True ):
780780 self .assertEqual (actual , expected )
781- self .assertIs (type (actual ), type (expected ))
781+ if typed :
782+ self .assertIs (type (actual ), type (expected ))
782783
783784 T = typing .TypeVar ('T' )
784785 S = typing .TypeVar ('S' )
785786 NT = typing .NewType ('NT' , str )
786787 x = int | T | bytes
787788
788- eq (x [str ], int | str | bytes )
789- eq (x [list [int ]], int | list [int ] | bytes )
789+ eq (x [str ], int | str | bytes , typed = False )
790+ eq (x [list [int ]], int | list [int ] | bytes , typed = False )
790791 eq (x [typing .List ], int | typing .List | bytes )
791792 eq (x [typing .List [int ]], int | typing .List [int ] | bytes )
792793 eq (x [typing .Hashable ], int | typing .Hashable | bytes )
793794 eq (x [collections .abc .Hashable ],
794- int | collections .abc .Hashable | bytes )
795+ int | collections .abc .Hashable | bytes , typed = False )
795796 eq (x [typing .Callable [[int ], str ]],
796797 int | typing .Callable [[int ], str ] | bytes )
797798 eq (x [collections .abc .Callable [[int ], str ]],
798- int | collections .abc .Callable [[int ], str ] | bytes )
799+ int | collections .abc .Callable [[int ], str ] | bytes , typed = False )
799800 eq (x [typing .Tuple [int , str ]], int | typing .Tuple [int , str ] | bytes )
800801 eq (x [typing .Literal ['none' ]], int | typing .Literal ['none' ] | bytes )
801- eq (x [str | list ], int | str | list | bytes )
802+ eq (x [str | list ], int | str | list | bytes , typed = False )
802803 eq (x [typing .Union [str , list ]], typing .Union [int , str , list , bytes ])
803- eq (x [str | int ], int | str | bytes )
804+ eq (x [str | int ], int | str | bytes , typed = False )
804805 eq (x [typing .Union [str , int ]], typing .Union [int , str , bytes ])
805806 eq (x [NT ], int | NT | bytes )
806807 eq (x [S ], int | S | bytes )
@@ -829,9 +830,9 @@ def test_union_from_args(self):
829830 with self .assertRaisesRegex (ValueError , r"args must be not empty" ):
830831 types .Union ._from_args (())
831832
832- alias = types .Union ._from_args ((int , str , T ))
833+ alias = types .Union ._from_args ((int , list [ T ], None ))
833834
834- self .assertEqual (alias .__args__ , (int , str , T ))
835+ self .assertEqual (alias .__args__ , (int , list [ T ], type ( None ) ))
835836 self .assertEqual (alias .__parameters__ , (T ,))
836837
837838 result = types .Union ._from_args ((int ,))
@@ -894,7 +895,6 @@ def test_or_type_repr(self):
894895 assert repr (int | None ) == "int | None"
895896 assert repr (int | type (None )) == "int | None"
896897 assert repr (int | typing .GenericAlias (list , int )) == "int | list[int]"
897- assert repr (int | typing .TypeVar ('T' )) == "int | ~T"
898898
899899 def test_or_type_operator_with_genericalias (self ):
900900 a = list [int ]
@@ -939,9 +939,9 @@ def __module__(self):
939939 TypeVar = BadMeta ('TypeVar' , (), {})
940940 _SpecialForm = BadMeta ('_SpecialForm' , (), {})
941941 # Crashes in Issue44483
942- with self .assertRaises (ZeroDivisionError ):
942+ with self .assertRaises (( TypeError , ZeroDivisionError ) ):
943943 str | TypeVar ()
944- with self .assertRaises (ZeroDivisionError ):
944+ with self .assertRaises (( TypeError , ZeroDivisionError ) ):
945945 str | _SpecialForm ()
946946
947947 @cpython_only
0 commit comments