@@ -33,14 +33,25 @@ _P = ParamSpec("_P")
33
33
_ExitFunc = Callable [[Optional [Type [BaseException ]], Optional [BaseException ], Optional [TracebackType ]], bool ]
34
34
_CM_EF = TypeVar ("_CM_EF" , AbstractContextManager [Any ], _ExitFunc )
35
35
36
- class _GeneratorContextManager ( AbstractContextManager [ _T_co ]) :
36
+ class ContextDecorator :
37
37
def __call__ (self , func : _F ) -> _F : ...
38
38
39
+ class _GeneratorContextManager (AbstractContextManager [_T_co ], ContextDecorator ): ...
40
+
39
41
# type ignore to deal with incomplete ParamSpec support in mypy
40
42
def contextmanager (func : Callable [_P , Iterator [_T ]]) -> Callable [_P , _GeneratorContextManager [_T ]]: ... # type: ignore[misc]
41
43
44
+ if sys .version_info >= (3 , 10 ):
45
+ _AF = TypeVar ("_AF" , bound = Callable [..., Awaitable [Any ]])
46
+ class AsyncContextDecorator :
47
+ def __call__ (self , func : _AF ) -> _AF : ...
48
+ class _AsyncGeneratorContextManager (AbstractAsyncContextManager [_T_co ], AsyncContextDecorator ): ...
49
+
50
+ elif sys .version_info >= (3 , 7 ):
51
+ class _AsyncGeneratorContextManager (AbstractAsyncContextManager [_T_co ]): ...
52
+
42
53
if sys .version_info >= (3 , 7 ):
43
- def asynccontextmanager (func : Callable [_P , AsyncIterator [_T ]]) -> Callable [_P , AbstractAsyncContextManager [_T ]]: ... # type: ignore[misc]
54
+ def asynccontextmanager (func : Callable [_P , AsyncIterator [_T ]]) -> Callable [_P , _AsyncGeneratorContextManager [_T ]]: ... # type: ignore[misc]
44
55
45
56
class _SupportsClose (Protocol ):
46
57
def close (self ) -> object : ...
@@ -56,9 +67,6 @@ if sys.version_info >= (3, 10):
56
67
_SupportsAcloseT = TypeVar ("_SupportsAcloseT" , bound = _SupportsAclose )
57
68
class aclosing (AbstractAsyncContextManager [_SupportsAcloseT ]):
58
69
def __init__ (self , thing : _SupportsAcloseT ) -> None : ...
59
- _AF = TypeVar ("_AF" , bound = Callable [..., Awaitable [Any ]])
60
- class AsyncContextDecorator :
61
- def __call__ (self , func : _AF ) -> _AF : ...
62
70
63
71
class suppress (AbstractContextManager [None ]):
64
72
def __init__ (self , * exceptions : Type [BaseException ]) -> None : ...
@@ -72,9 +80,6 @@ class redirect_stdout(AbstractContextManager[_T_io]):
72
80
class redirect_stderr (AbstractContextManager [_T_io ]):
73
81
def __init__ (self , new_target : _T_io ) -> None : ...
74
82
75
- class ContextDecorator :
76
- def __call__ (self , func : _F ) -> _F : ...
77
-
78
83
class ExitStack (AbstractContextManager [ExitStack ]):
79
84
def __init__ (self ) -> None : ...
80
85
def enter_context (self , cm : AbstractContextManager [_T ]) -> _T : ...
0 commit comments