@@ -315,6 +315,8 @@ def test_repr(self):
315315 self .assertEqual (repr (u ), 'typing.Union[typing.List[int], int]' )
316316 u = Union [list [int ], dict [str , float ]]
317317 self .assertEqual (repr (u ), 'typing.Union[list[int], dict[str, float]]' )
318+ u = Union [int | float ]
319+ self .assertEqual (repr (u ), 'typing.Union[int, float]' )
318320
319321 def test_cannot_subclass (self ):
320322 with self .assertRaises (TypeError ):
@@ -1449,6 +1451,8 @@ def test_basics(self):
14491451 with self .assertRaises (TypeError ):
14501452 issubclass (SM1 , SimpleMapping )
14511453 self .assertIsInstance (SM1 (), SimpleMapping )
1454+ T = TypeVar ("T" )
1455+ self .assertEqual (List [list [T ] | float ].__parameters__ , (T ,))
14521456
14531457 def test_generic_errors (self ):
14541458 T = TypeVar ('T' )
@@ -1785,6 +1789,7 @@ def test_extended_generic_rules_repr(self):
17851789 def test_generic_forward_ref (self ):
17861790 def foobar (x : List [List ['CC' ]]): ...
17871791 def foobar2 (x : list [list [ForwardRef ('CC' )]]): ...
1792+ def foobar3 (x : list [ForwardRef ('CC | int' )] | int ): ...
17881793 class CC : ...
17891794 self .assertEqual (
17901795 get_type_hints (foobar , globals (), locals ()),
@@ -1794,6 +1799,10 @@ class CC: ...
17941799 get_type_hints (foobar2 , globals (), locals ()),
17951800 {'x' : list [list [CC ]]}
17961801 )
1802+ self .assertEqual (
1803+ get_type_hints (foobar3 , globals (), locals ()),
1804+ {'x' : list [CC | int ] | int }
1805+ )
17971806
17981807 T = TypeVar ('T' )
17991808 AT = Tuple [T , ...]
@@ -2467,6 +2476,12 @@ def foo(a: Union['T']):
24672476 self .assertEqual (get_type_hints (foo , globals (), locals ()),
24682477 {'a' : Union [T ]})
24692478
2479+ def foo (a : tuple [ForwardRef ('T' )] | int ):
2480+ pass
2481+
2482+ self .assertEqual (get_type_hints (foo , globals (), locals ()),
2483+ {'a' : tuple [T ] | int })
2484+
24702485 def test_tuple_forward (self ):
24712486
24722487 def foo (a : Tuple ['T' ]):
@@ -2851,7 +2866,7 @@ def test_get_type_hints_from_various_objects(self):
28512866 gth (None )
28522867
28532868 def test_get_type_hints_modules (self ):
2854- ann_module_type_hints = {1 : 2 , 'f' : Tuple [int , int ], 'x' : int , 'y' : str }
2869+ ann_module_type_hints = {1 : 2 , 'f' : Tuple [int , int ], 'x' : int , 'y' : str , 'u' : int | float }
28552870 self .assertEqual (gth (ann_module ), ann_module_type_hints )
28562871 self .assertEqual (gth (ann_module2 ), {})
28572872 self .assertEqual (gth (ann_module3 ), {})
@@ -4393,6 +4408,9 @@ def test_no_paramspec_in__parameters__(self):
43934408 self .assertNotIn (P , list [P ].__parameters__ )
43944409 self .assertIn (T , tuple [T , P ].__parameters__ )
43954410
4411+ self .assertNotIn (P , (list [P ] | int ).__parameters__ )
4412+ self .assertIn (T , (tuple [T , P ] | int ).__parameters__ )
4413+
43964414 def test_paramspec_in_nested_generics (self ):
43974415 # Although ParamSpec should not be found in __parameters__ of most
43984416 # generics, they probably should be found when nested in
@@ -4402,8 +4420,10 @@ def test_paramspec_in_nested_generics(self):
44024420 C1 = Callable [P , T ]
44034421 G1 = List [C1 ]
44044422 G2 = list [C1 ]
4423+ G3 = list [C1 ] | int
44054424 self .assertEqual (G1 .__parameters__ , (P , T ))
44064425 self .assertEqual (G2 .__parameters__ , (P , T ))
4426+ self .assertEqual (G3 .__parameters__ , (P , T ))
44074427
44084428
44094429class ConcatenateTests (BaseTestCase ):
0 commit comments