@@ -772,6 +772,36 @@ def test_union_parameter_chaining(self):
772772 self .assertEqual ((list [T ] | list [S ])[int , T ], list [int ] | list [T ])
773773 self .assertEqual ((list [T ] | list [S ])[int , int ], list [int ])
774774
775+ def test_union_parameter_substitution (self ):
776+ def eq (actual , expected ):
777+ self .assertEqual (actual , expected )
778+ self .assertIs (type (actual ), type (expected ))
779+
780+ T = typing .TypeVar ('T' )
781+ S = typing .TypeVar ('S' )
782+ NT = typing .NewType ('NT' , str )
783+ x = int | T | bytes
784+
785+ eq (x [str ], int | str | bytes )
786+ eq (x [list [int ]], int | list [int ] | bytes )
787+ eq (x [typing .List ], int | typing .List | bytes )
788+ eq (x [typing .List [int ]], int | typing .List [int ] | bytes )
789+ eq (x [typing .Hashable ], int | typing .Hashable | bytes )
790+ eq (x [collections .abc .Hashable ],
791+ int | collections .abc .Hashable | bytes )
792+ eq (x [typing .Callable [[int ], str ]],
793+ int | typing .Callable [[int ], str ] | bytes )
794+ eq (x [collections .abc .Callable [[int ], str ]],
795+ int | collections .abc .Callable [[int ], str ] | bytes )
796+ eq (x [typing .Tuple [int , str ]], int | typing .Tuple [int , str ] | bytes )
797+ eq (x [typing .Literal ['none' ]], int | typing .Literal ['none' ] | bytes )
798+ eq (x [str | list ], int | str | list | bytes )
799+ eq (x [typing .Union [str , list ]], typing .Union [int , str , list , bytes ])
800+ eq (x [str | int ], int | str | bytes )
801+ eq (x [typing .Union [str , int ]], typing .Union [int , str , bytes ])
802+ eq (x [NT ], int | NT | bytes )
803+ eq (x [S ], int | S | bytes )
804+
775805 def test_union_parameter_substitution_errors (self ):
776806 T = typing .TypeVar ("T" )
777807 x = int | T
0 commit comments