@@ -4,7 +4,6 @@ from types import TracebackType
4
4
from typing import (
5
5
IO ,
6
6
Any ,
7
- AsyncContextManager ,
8
7
AsyncIterator ,
9
8
Awaitable ,
10
9
Callable ,
@@ -20,6 +19,8 @@ from typing_extensions import ParamSpec, Protocol
20
19
21
20
AbstractContextManager = ContextManager
22
21
if sys .version_info >= (3 , 7 ):
22
+ from typing import AsyncContextManager
23
+
23
24
AbstractAsyncContextManager = AsyncContextManager
24
25
25
26
_T = TypeVar ("_T" )
@@ -29,53 +30,53 @@ _F = TypeVar("_F", bound=Callable[..., Any])
29
30
_P = ParamSpec ("_P" )
30
31
31
32
_ExitFunc = Callable [[Optional [Type [BaseException ]], Optional [BaseException ], Optional [TracebackType ]], bool ]
32
- _CM_EF = TypeVar ("_CM_EF" , ContextManager [Any ], _ExitFunc )
33
+ _CM_EF = TypeVar ("_CM_EF" , AbstractContextManager [Any ], _ExitFunc )
33
34
34
- class _GeneratorContextManager (ContextManager [_T_co ]):
35
+ class _GeneratorContextManager (AbstractContextManager [_T_co ]):
35
36
def __call__ (self , func : _F ) -> _F : ...
36
37
37
38
# type ignore to deal with incomplete ParamSpec support in mypy
38
39
def contextmanager (func : Callable [_P , Iterator [_T ]]) -> Callable [_P , _GeneratorContextManager [_T ]]: ... # type: ignore
39
40
40
41
if sys .version_info >= (3 , 7 ):
41
- def asynccontextmanager (func : Callable [_P , AsyncIterator [_T ]]) -> Callable [_P , AsyncContextManager [_T ]]: ... # type: ignore
42
+ def asynccontextmanager (func : Callable [_P , AsyncIterator [_T ]]) -> Callable [_P , AbstractAsyncContextManager [_T ]]: ... # type: ignore
42
43
43
44
class _SupportsClose (Protocol ):
44
45
def close (self ) -> object : ...
45
46
46
47
_SupportsCloseT = TypeVar ("_SupportsCloseT" , bound = _SupportsClose )
47
48
48
- class closing (ContextManager [_SupportsCloseT ]):
49
+ class closing (AbstractContextManager [_SupportsCloseT ]):
49
50
def __init__ (self , thing : _SupportsCloseT ) -> None : ...
50
51
51
52
if sys .version_info >= (3 , 10 ):
52
53
class _SupportsAclose (Protocol ):
53
54
def aclose (self ) -> Awaitable [object ]: ...
54
55
_SupportsAcloseT = TypeVar ("_SupportsAcloseT" , bound = _SupportsAclose )
55
- class aclosing (AsyncContextManager [_SupportsAcloseT ]):
56
+ class aclosing (AbstractAsyncContextManager [_SupportsAcloseT ]):
56
57
def __init__ (self , thing : _SupportsAcloseT ) -> None : ...
57
58
_AF = TypeVar ("_AF" , bound = Callable [..., Awaitable [Any ]])
58
59
class AsyncContextDecorator :
59
60
def __call__ (self , func : _AF ) -> _AF : ...
60
61
61
- class suppress (ContextManager [None ]):
62
+ class suppress (AbstractContextManager [None ]):
62
63
def __init__ (self , * exceptions : Type [BaseException ]) -> None : ...
63
64
def __exit__ (
64
65
self , exctype : Type [BaseException ] | None , excinst : BaseException | None , exctb : TracebackType | None
65
66
) -> bool : ...
66
67
67
- class redirect_stdout (ContextManager [_T_io ]):
68
+ class redirect_stdout (AbstractContextManager [_T_io ]):
68
69
def __init__ (self , new_target : _T_io ) -> None : ...
69
70
70
- class redirect_stderr (ContextManager [_T_io ]):
71
+ class redirect_stderr (AbstractContextManager [_T_io ]):
71
72
def __init__ (self , new_target : _T_io ) -> None : ...
72
73
73
74
class ContextDecorator :
74
75
def __call__ (self , func : _F ) -> _F : ...
75
76
76
- class ExitStack (ContextManager [ExitStack ]):
77
+ class ExitStack (AbstractContextManager [ExitStack ]):
77
78
def __init__ (self ) -> None : ...
78
- def enter_context (self , cm : ContextManager [_T ]) -> _T : ...
79
+ def enter_context (self , cm : AbstractContextManager [_T ]) -> _T : ...
79
80
def push (self , exit : _CM_EF ) -> _CM_EF : ...
80
81
def callback (self , __callback : Callable [..., Any ], * args : Any , ** kwds : Any ) -> Callable [..., Any ]: ...
81
82
def pop_all (self : Self ) -> Self : ...
@@ -88,11 +89,11 @@ class ExitStack(ContextManager[ExitStack]):
88
89
if sys .version_info >= (3 , 7 ):
89
90
_ExitCoroFunc = Callable [[Optional [Type [BaseException ]], Optional [BaseException ], Optional [TracebackType ]], Awaitable [bool ]]
90
91
_CallbackCoroFunc = Callable [..., Awaitable [Any ]]
91
- _ACM_EF = TypeVar ("_ACM_EF" , AsyncContextManager [Any ], _ExitCoroFunc )
92
- class AsyncExitStack (AsyncContextManager [AsyncExitStack ]):
92
+ _ACM_EF = TypeVar ("_ACM_EF" , AbstractAsyncContextManager [Any ], _ExitCoroFunc )
93
+ class AsyncExitStack (AbstractAsyncContextManager [AsyncExitStack ]):
93
94
def __init__ (self ) -> None : ...
94
- def enter_context (self , cm : ContextManager [_T ]) -> _T : ...
95
- def enter_async_context (self , cm : AsyncContextManager [_T ]) -> Awaitable [_T ]: ...
95
+ def enter_context (self , cm : AbstractContextManager [_T ]) -> _T : ...
96
+ def enter_async_context (self , cm : AbstractAsyncContextManager [_T ]) -> Awaitable [_T ]: ...
96
97
def push (self , exit : _CM_EF ) -> _CM_EF : ...
97
98
def push_async_exit (self , exit : _ACM_EF ) -> _ACM_EF : ...
98
99
def callback (self , __callback : Callable [..., Any ], * args : Any , ** kwds : Any ) -> Callable [..., Any ]: ...
0 commit comments