@@ -2,7 +2,7 @@ import abc
22import sys
33from _typeshed import FileDescriptorOrPath , Unused
44from abc import ABC , abstractmethod
5- from collections .abc import AsyncGenerator , AsyncIterator , Awaitable , Callable , Generator , Iterator
5+ from collections .abc import AsyncIterator , Awaitable , Callable , Generator , Iterator
66from types import TracebackType
77from typing import IO , Any , Generic , Protocol , TypeVar , overload , runtime_checkable
88from typing_extensions import ParamSpec , Self , TypeAlias
@@ -64,16 +64,15 @@ class ContextDecorator:
6464 def _recreate_cm (self ) -> Self : ...
6565 def __call__ (self , func : _F ) -> _F : ...
6666
67- class _GeneratorContextManagerBase : ...
68-
69- class _GeneratorContextManager (_GeneratorContextManagerBase , AbstractContextManager [_T_co , bool | None ], ContextDecorator ):
70- # __init__ and all instance attributes are actually inherited from _GeneratorContextManagerBase
71- # adding them there is more trouble than it's worth to include in the stub; see #6676
67+ class _GeneratorContextManagerBase (Generic [_T_co ]):
68+ # Ideally this would use Paramspec, but that requires (*args, **kwargs), which this isn't. see #6676
7269 def __init__ (self , func : Callable [..., Iterator [_T_co ]], args : tuple [Any , ...], kwds : dict [str , Any ]) -> None : ...
7370 gen : Generator [_T_co , Any , Any ]
7471 func : Callable [..., Generator [_T_co , Any , Any ]]
7572 args : tuple [Any , ...]
7673 kwds : dict [str , Any ]
74+
75+ class _GeneratorContextManager (_GeneratorContextManagerBase [_T_co ], AbstractContextManager [_T_co , bool | None ], ContextDecorator ):
7776 if sys .version_info >= (3 , 9 ):
7877 def __exit__ (
7978 self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
@@ -93,26 +92,14 @@ if sys.version_info >= (3, 10):
9392 def __call__ (self , func : _AF ) -> _AF : ...
9493
9594 class _AsyncGeneratorContextManager (
96- _GeneratorContextManagerBase , AbstractAsyncContextManager [_T_co , bool | None ], AsyncContextDecorator
95+ _GeneratorContextManagerBase [ _T_co ] , AbstractAsyncContextManager [_T_co , bool | None ], AsyncContextDecorator
9796 ):
98- # __init__ and these attributes are actually defined in the base class _GeneratorContextManagerBase,
99- # adding them there is more trouble than it's worth to include in the stub (see #6676)
100- def __init__ (self , func : Callable [..., AsyncIterator [_T_co ]], args : tuple [Any , ...], kwds : dict [str , Any ]) -> None : ...
101- gen : AsyncGenerator [_T_co , Any ]
102- func : Callable [..., AsyncGenerator [_T_co , Any ]]
103- args : tuple [Any , ...]
104- kwds : dict [str , Any ]
10597 async def __aexit__ (
10698 self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
10799 ) -> bool | None : ...
108100
109101else :
110- class _AsyncGeneratorContextManager (_GeneratorContextManagerBase , AbstractAsyncContextManager [_T_co , bool | None ]):
111- def __init__ (self , func : Callable [..., AsyncIterator [_T_co ]], args : tuple [Any , ...], kwds : dict [str , Any ]) -> None : ...
112- gen : AsyncGenerator [_T_co , Any ]
113- func : Callable [..., AsyncGenerator [_T_co , Any ]]
114- args : tuple [Any , ...]
115- kwds : dict [str , Any ]
102+ class _AsyncGeneratorContextManager (_GeneratorContextManagerBase [_T_co ], AbstractAsyncContextManager [_T_co , bool | None ]):
116103 async def __aexit__ (
117104 self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
118105 ) -> bool | None : ...
0 commit comments