2222from  typing  import  NamedTuple , TypedDict 
2323from  typing  import  IO , TextIO , BinaryIO 
2424from  typing  import  Pattern , Match 
25- from  typing  import  Annotated 
25+ from  typing  import  Annotated ,  ForwardRef 
2626import  abc 
2727import  typing 
2828import  weakref 
@@ -1756,11 +1756,17 @@ def test_extended_generic_rules_repr(self):
17561756
17571757    def  test_generic_forward_ref (self ):
17581758        def  foobar (x : List [List ['CC' ]]): ...
1759+         def  foobar2 (x : list [list [ForwardRef ('CC' )]]): ...
17591760        class  CC : ...
17601761        self .assertEqual (
17611762            get_type_hints (foobar , globals (), locals ()),
17621763            {'x' : List [List [CC ]]}
17631764        )
1765+         self .assertEqual (
1766+             get_type_hints (foobar2 , globals (), locals ()),
1767+             {'x' : list [list [CC ]]}
1768+         )
1769+ 
17641770        T  =  TypeVar ('T' )
17651771        AT  =  Tuple [T , ...]
17661772        def  barfoo (x : AT ): ...
@@ -2446,6 +2452,12 @@ def foo(a: Tuple['T']):
24462452        self .assertEqual (get_type_hints (foo , globals (), locals ()),
24472453                         {'a' : Tuple [T ]})
24482454
2455+         def  foo (a : tuple [ForwardRef ('T' )]):
2456+             pass 
2457+ 
2458+         self .assertEqual (get_type_hints (foo , globals (), locals ()),
2459+                          {'a' : tuple [T ]})
2460+ 
24492461    def  test_forward_recursion_actually (self ):
24502462        def  namespace1 ():
24512463            a  =  typing .ForwardRef ('A' )
@@ -2909,19 +2921,41 @@ def foobar(x: List['X']): ...
29092921            get_type_hints (foobar , globals (), locals (), include_extras = True ),
29102922            {'x' : List [Annotated [int , (1 , 10 )]]}
29112923        )
2924+ 
2925+         def  foobar (x : list [ForwardRef ('X' )]): ...
2926+         X  =  Annotated [int , (1 , 10 )]
2927+         self .assertEqual (
2928+             get_type_hints (foobar , globals (), locals ()),
2929+             {'x' : list [int ]}
2930+         )
2931+         self .assertEqual (
2932+             get_type_hints (foobar , globals (), locals (), include_extras = True ),
2933+             {'x' : list [Annotated [int , (1 , 10 )]]}
2934+         )
2935+ 
29122936        BA  =  Tuple [Annotated [T , (1 , 0 )], ...]
29132937        def  barfoo (x : BA ): ...
29142938        self .assertEqual (get_type_hints (barfoo , globals (), locals ())['x' ], Tuple [T , ...])
29152939        self .assertIs (
29162940            get_type_hints (barfoo , globals (), locals (), include_extras = True )['x' ],
29172941            BA 
29182942        )
2943+ 
2944+         BA  =  tuple [Annotated [T , (1 , 0 )], ...]
2945+         def  barfoo (x : BA ): ...
2946+         self .assertEqual (get_type_hints (barfoo , globals (), locals ())['x' ], tuple [T , ...])
2947+         self .assertIs (
2948+             get_type_hints (barfoo , globals (), locals (), include_extras = True )['x' ],
2949+             BA 
2950+         )
2951+ 
29192952        def  barfoo2 (x : typing .Callable [..., Annotated [List [T ], "const" ]],
29202953                    y : typing .Union [int , Annotated [T , "mutable" ]]): ...
29212954        self .assertEqual (
29222955            get_type_hints (barfoo2 , globals (), locals ()),
29232956            {'x' : typing .Callable [..., List [T ]], 'y' : typing .Union [int , T ]}
29242957        )
2958+ 
29252959        BA2  =  typing .Callable [..., List [T ]]
29262960        def  barfoo3 (x : BA2 ): ...
29272961        self .assertIs (
@@ -2972,6 +3006,9 @@ class C(Generic[T]): pass
29723006        self .assertIs (get_origin (Generic [T ]), Generic )
29733007        self .assertIs (get_origin (List [Tuple [T , T ]][int ]), list )
29743008        self .assertIs (get_origin (Annotated [T , 'thing' ]), Annotated )
3009+         self .assertIs (get_origin (List ), list )
3010+         self .assertIs (get_origin (list [int ]), list )
3011+         self .assertIs (get_origin (list ), None )
29753012
29763013    def  test_get_args (self ):
29773014        T  =  TypeVar ('T' )
@@ -2993,6 +3030,9 @@ class C(Generic[T]): pass
29933030        self .assertEqual (get_args (Tuple [int , ...]), (int , ...))
29943031        self .assertEqual (get_args (Tuple [()]), ((),))
29953032        self .assertEqual (get_args (Annotated [T , 'one' , 2 , ['three' ]]), (T , 'one' , 2 , ['three' ]))
3033+         self .assertEqual (get_args (List ), (typing .T ,))
3034+         self .assertEqual (get_args (list [int ]), (int ,))
3035+         self .assertEqual (get_args (list ), ())
29963036
29973037
29983038class  CollectionsAbcTests (BaseTestCase ):
0 commit comments