@@ -33,14 +33,25 @@ _P = ParamSpec("_P")
3333_ExitFunc = Callable [[Optional [Type [BaseException ]], Optional [BaseException ], Optional [TracebackType ]], bool ]
3434_CM_EF = TypeVar ("_CM_EF" , AbstractContextManager [Any ], _ExitFunc )
3535
36- class _GeneratorContextManager ( AbstractContextManager [ _T_co ]) :
36+ class ContextDecorator :
3737 def __call__ (self , func : _F ) -> _F : ...
3838
39+ class _GeneratorContextManager (AbstractContextManager [_T_co ], ContextDecorator ): ...
40+
3941# type ignore to deal with incomplete ParamSpec support in mypy
4042def contextmanager (func : Callable [_P , Iterator [_T ]]) -> Callable [_P , _GeneratorContextManager [_T ]]: ... # type: ignore[misc]
4143
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+
4253if 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]
4455
4556class _SupportsClose (Protocol ):
4657 def close (self ) -> object : ...
@@ -56,9 +67,6 @@ if sys.version_info >= (3, 10):
5667 _SupportsAcloseT = TypeVar ("_SupportsAcloseT" , bound = _SupportsAclose )
5768 class aclosing (AbstractAsyncContextManager [_SupportsAcloseT ]):
5869 def __init__ (self , thing : _SupportsAcloseT ) -> None : ...
59- _AF = TypeVar ("_AF" , bound = Callable [..., Awaitable [Any ]])
60- class AsyncContextDecorator :
61- def __call__ (self , func : _AF ) -> _AF : ...
6270
6371class suppress (AbstractContextManager [None ]):
6472 def __init__ (self , * exceptions : Type [BaseException ]) -> None : ...
@@ -72,9 +80,6 @@ class redirect_stdout(AbstractContextManager[_T_io]):
7280class redirect_stderr (AbstractContextManager [_T_io ]):
7381 def __init__ (self , new_target : _T_io ) -> None : ...
7482
75- class ContextDecorator :
76- def __call__ (self , func : _F ) -> _F : ...
77-
7883class ExitStack (AbstractContextManager [ExitStack ]):
7984 def __init__ (self ) -> None : ...
8085 def enter_context (self , cm : AbstractContextManager [_T ]) -> _T : ...
0 commit comments