@@ -18,6 +18,11 @@ class Example:
1818
1919class Forward : ...
2020
21+ def clear_typing_caches ():
22+ for f in typing ._cleanups :
23+ f ()
24+
25+
2126class TypesTests (unittest .TestCase ):
2227
2328 def test_truth_values (self ):
@@ -710,11 +715,34 @@ def test_or_type_operator_with_TypeVar(self):
710715 self .assertIs ((TV | int )[int ], int )
711716
712717 def test_union_args (self ):
713- self .assertEqual ((int | str ).__args__ , (int , str ))
714- self .assertEqual (((int | str ) | list ).__args__ , (int , str , list ))
715- self .assertEqual ((int | (str | list )).__args__ , (int , str , list ))
716- self .assertEqual ((int | None ).__args__ , (int , type (None )))
717- self .assertEqual ((int | type (None )).__args__ , (int , type (None )))
718+ def check (arg , expected ):
719+ clear_typing_caches ()
720+ self .assertEqual (arg .__args__ , expected )
721+
722+ check (int | str , (int , str ))
723+ check ((int | str ) | list , (int , str , list ))
724+ check (int | (str | list ), (int , str , list ))
725+ check ((int | str ) | int , (int , str ))
726+ check (int | (str | int ), (int , str ))
727+ check ((int | str ) | (str | int ), (int , str ))
728+ check (typing .Union [int , str ] | list , (int , str , list ))
729+ check (int | typing .Union [str , list ], (int , str , list ))
730+ check ((int | str ) | (list | int ), (int , str , list ))
731+ check ((int | str ) | typing .Union [list , int ], (int , str , list ))
732+ check (typing .Union [int , str ] | (list | int ), (int , str , list ))
733+ check ((str | int ) | (int | list ), (str , int , list ))
734+ check ((str | int ) | typing .Union [int , list ], (str , int , list ))
735+ check (typing .Union [str , int ] | (int | list ), (str , int , list ))
736+ check (int | type (None ), (int , type (None )))
737+ check (type (None ) | int , (type (None ), int ))
738+
739+ args = (int , list [int ], typing .List [int ],
740+ typing .Tuple [int , int ], typing .Callable [[int ], int ],
741+ typing .Hashable , typing .TypeVar ('T' ))
742+ for x in args :
743+ with self .subTest (x ):
744+ check (x | None , (x , type (None )))
745+ check (None | x , (type (None ), x ))
718746
719747 def test_union_parameter_chaining (self ):
720748 T = typing .TypeVar ("T" )
0 commit comments