@@ -2,7 +2,7 @@ import abc
2
2
import sys
3
3
from _typeshed import FileDescriptorOrPath , Unused
4
4
from 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
6
6
from types import TracebackType
7
7
from typing import IO , Any , Generic , Protocol , TypeVar , overload , runtime_checkable
8
8
from typing_extensions import ParamSpec , Self , TypeAlias
@@ -64,16 +64,15 @@ class ContextDecorator:
64
64
def _recreate_cm (self ) -> Self : ...
65
65
def __call__ (self , func : _F ) -> _F : ...
66
66
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
72
69
def __init__ (self , func : Callable [..., Iterator [_T_co ]], args : tuple [Any , ...], kwds : dict [str , Any ]) -> None : ...
73
70
gen : Generator [_T_co , Any , Any ]
74
71
func : Callable [..., Generator [_T_co , Any , Any ]]
75
72
args : tuple [Any , ...]
76
73
kwds : dict [str , Any ]
74
+
75
+ class _GeneratorContextManager (_GeneratorContextManagerBase [_T_co ], AbstractContextManager [_T_co , bool | None ], ContextDecorator ):
77
76
if sys .version_info >= (3 , 9 ):
78
77
def __exit__ (
79
78
self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
@@ -93,26 +92,14 @@ if sys.version_info >= (3, 10):
93
92
def __call__ (self , func : _AF ) -> _AF : ...
94
93
95
94
class _AsyncGeneratorContextManager (
96
- _GeneratorContextManagerBase , AbstractAsyncContextManager [_T_co , bool | None ], AsyncContextDecorator
95
+ _GeneratorContextManagerBase [ _T_co ] , AbstractAsyncContextManager [_T_co , bool | None ], AsyncContextDecorator
97
96
):
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 ]
105
97
async def __aexit__ (
106
98
self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
107
99
) -> bool | None : ...
108
100
109
101
else :
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 ]):
116
103
async def __aexit__ (
117
104
self , typ : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
118
105
) -> bool | None : ...
0 commit comments