@@ -5499,6 +5499,25 @@ def foobar(x: List['X']): ...
5499
5499
get_type_hints (foobar , globals (), locals (), include_extras = True ),
5500
5500
{'x' : List [Annotated [int , (1 , 10 )]]}
5501
5501
)
5502
+ def foobar2 (x : list ['X' ]): ...
5503
+ if sys .version_info >= (3 , 11 ):
5504
+ self .assertEqual (
5505
+ get_type_hints (foobar2 , globals (), locals ()),
5506
+ {'x' : list [int ]}
5507
+ )
5508
+ self .assertEqual (
5509
+ get_type_hints (foobar2 , globals (), locals (), include_extras = True ),
5510
+ {'x' : list [Annotated [int , (1 , 10 )]]}
5511
+ )
5512
+ else : # TODO: evaluate nested forward refs in Python < 3.11
5513
+ self .assertEqual (
5514
+ get_type_hints (foobar2 , globals (), locals ()),
5515
+ {'x' : list ['X' ]}
5516
+ )
5517
+ self .assertEqual (
5518
+ get_type_hints (foobar2 , globals (), locals (), include_extras = True ),
5519
+ {'x' : list ['X' ]}
5520
+ )
5502
5521
BA = Tuple [Annotated [T , (1 , 0 )], ...]
5503
5522
def barfoo (x : BA ): ...
5504
5523
self .assertEqual (get_type_hints (barfoo , globals (), locals ())['x' ], Tuple [T , ...])
@@ -5973,6 +5992,15 @@ def run():
5973
5992
# The actual test:
5974
5993
self .assertEqual (result1 , result2 )
5975
5994
5995
+ def test_subclass (self ):
5996
+ if sys .version_info >= (3 , 10 ):
5997
+ with self .assertRaises (TypeError ):
5998
+ class MyParamSpec (ParamSpec ):
5999
+ pass
6000
+ else :
6001
+ class MyParamSpec (ParamSpec ): # Does not raise
6002
+ pass
6003
+
5976
6004
5977
6005
class ConcatenateTests (BaseTestCase ):
5978
6006
def test_basics (self ):
@@ -6382,6 +6410,14 @@ def test_pickle(self):
6382
6410
pickled = pickle .dumps (Self , protocol = proto )
6383
6411
self .assertIs (Self , pickle .loads (pickled ))
6384
6412
6413
+ @skipUnless (TYPING_3_10_0 , "PEP 604 has yet to be" )
6414
+ def test_or (self ):
6415
+ self .assertEqual (Self | int , Union [Self , int ])
6416
+ self .assertEqual (int | Self , Union [int , Self ])
6417
+
6418
+ self .assertEqual (get_args (Self | int ), (Self , int ))
6419
+ self .assertEqual (get_args (int | Self ), (int , Self ))
6420
+
6385
6421
6386
6422
class UnpackTests (BaseTestCase ):
6387
6423
def test_basic_plain (self ):
0 commit comments