@@ -7511,6 +7511,15 @@ def manager():
75117511 self .assertIsInstance (cm , typing .ContextManager )
75127512 self .assertNotIsInstance (42 , typing .ContextManager )
75137513
7514+ def test_contextmanager_type_params (self ):
7515+ cm1 = typing .ContextManager [int ]
7516+ self .assertEqual (get_args (cm1 ), (int , bool | None ))
7517+ cm2 = typing .ContextManager [int , None ]
7518+ self .assertEqual (get_args (cm2 ), (int , types .NoneType ))
7519+
7520+ type gen_cm [T1 , T2 ] = typing .ContextManager [T1 , T2 ]
7521+ self .assertEqual (get_args (gen_cm .__value__ [int , None ]), (int , types .NoneType ))
7522+
75147523 def test_async_contextmanager (self ):
75157524 class NotACM :
75167525 pass
@@ -7522,11 +7531,17 @@ def manager():
75227531
75237532 cm = manager ()
75247533 self .assertNotIsInstance (cm , typing .AsyncContextManager )
7525- self .assertEqual (typing .AsyncContextManager [int ].__args__ , (int ,))
7534+ self .assertEqual (typing .AsyncContextManager [int ].__args__ , (int , bool | None ))
75267535 with self .assertRaises (TypeError ):
75277536 isinstance (42 , typing .AsyncContextManager [int ])
75287537 with self .assertRaises (TypeError ):
7529- typing .AsyncContextManager [int , str ]
7538+ typing .AsyncContextManager [int , str , float ]
7539+
7540+ def test_asynccontextmanager_type_params (self ):
7541+ cm1 = typing .AsyncContextManager [int ]
7542+ self .assertEqual (get_args (cm1 ), (int , bool | None ))
7543+ cm2 = typing .AsyncContextManager [int , None ]
7544+ self .assertEqual (get_args (cm2 ), (int , types .NoneType ))
75307545
75317546
75327547class TypeTests (BaseTestCase ):
@@ -9953,7 +9968,7 @@ def test_special_attrs(self):
99539968 typing .ValuesView : 'ValuesView' ,
99549969 # Subscribed ABC classes
99559970 typing .AbstractSet [Any ]: 'AbstractSet' ,
9956- typing .AsyncContextManager [Any ]: 'AsyncContextManager' ,
9971+ typing .AsyncContextManager [Any , Any ]: 'AsyncContextManager' ,
99579972 typing .AsyncGenerator [Any , Any ]: 'AsyncGenerator' ,
99589973 typing .AsyncIterable [Any ]: 'AsyncIterable' ,
99599974 typing .AsyncIterator [Any ]: 'AsyncIterator' ,
@@ -9963,7 +9978,7 @@ def test_special_attrs(self):
99639978 typing .ChainMap [Any , Any ]: 'ChainMap' ,
99649979 typing .Collection [Any ]: 'Collection' ,
99659980 typing .Container [Any ]: 'Container' ,
9966- typing .ContextManager [Any ]: 'ContextManager' ,
9981+ typing .ContextManager [Any , Any ]: 'ContextManager' ,
99679982 typing .Coroutine [Any , Any , Any ]: 'Coroutine' ,
99689983 typing .Counter [Any ]: 'Counter' ,
99699984 typing .DefaultDict [Any , Any ]: 'DefaultDict' ,
0 commit comments