Format: application/octet-stream
1 import sys
2 from types import TracebackType
3 from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Optional, Type, TypeVar, overload
4
5 if sys.version_info >= (3, 5):
6 from typing import AsyncContextManager, AsyncIterator
7
8 if sys.version_info >= (3, 6):
9 AbstractContextManager = ContextManager
10 if sys.version_info >= (3, 7):
11 AbstractAsyncContextManager = AsyncContextManager
12
13 _T = TypeVar("_T")
14 _T_co = TypeVar("_T_co", covariant=True)
15 _T_io = TypeVar("_T_io", bound=Optional[IO[str]])
16 _F = TypeVar("_F", bound=Callable[..., Any])
17
18 _ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
19 _CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc)
20
21 if sys.version_info >= (3, 2):
22 class _GeneratorContextManager(ContextManager[_T_co]):
23 def __call__(self, func: _F) -> _F: ...
24 def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ...
25
26 else:
27 class GeneratorContextManager(ContextManager[_T_co]):
28 def __call__(self, func: _F) -> _F: ...
29 def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
30
31 if sys.version_info >= (3, 7):
32 def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ...
33
34 if sys.version_info < (3,):
35 def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...
36
37 class closing(ContextManager[_T]):
38 def __init__(self, thing: _T) -> None: ...
39
40 if sys.version_info >= (3, 4):
41 class suppress(ContextManager[None]):
42 def __init__(self, *exceptions: Type[BaseException]) -> None: ...
43 def __exit__(
44 self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]
45 ) -> bool: ...
46 class redirect_stdout(ContextManager[_T_io]):
47 def __init__(self, new_target: _T_io) -> None: ...
48
49 if sys.version_info >= (3, 5):
50 class redirect_stderr(ContextManager[_T_io]):
51 def __init__(self, new_target: _T_io) -> None: ...
52
53 if sys.version_info >= (3,):
54 class ContextDecorator:
55 def __call__(self, func: _F) -> _F: ...
56 _U = TypeVar("_U", bound=ExitStack)
57 class ExitStack(ContextManager[ExitStack]):
58 def __init__(self) -> None: ...
59 def enter_context(self, cm: ContextManager[_T]) -> _T: ...
60 def push(self, exit: _CM_EF) -> _CM_EF: ...
61 def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
62 def pop_all(self: _U) -> _U: ...
63 def close(self) -> None: ...
64 def __enter__(self: _U) -> _U: ...
65 def __exit__(
66 self,
67 __exc_type: Optional[Type[BaseException]],
68 __exc_value: Optional[BaseException],
69 __traceback: Optional[TracebackType],
70 ) -> bool: ...
71
72 if sys.version_info >= (3, 7):
73 from typing import Awaitable
74
75 _S = TypeVar("_S", bound=AsyncExitStack)
76
77 _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
78 _CallbackCoroFunc = Callable[..., Awaitable[Any]]
79 _ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc)
80 class AsyncExitStack(AsyncContextManager[AsyncExitStack]):
81 def __init__(self) -> None: ...
82 def enter_context(self, cm: ContextManager[_T]) -> _T: ...
83 def enter_async_context(self, cm: AsyncContextManager[_T]) -> Awaitable[_T]: ...
84 def push(self, exit: _CM_EF) -> _CM_EF: ...
85 def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
86 def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
87 def push_async_callback(self, callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
88 def pop_all(self: _S) -> _S: ...
89 def aclose(self) -> Awaitable[None]: ...
90 def __aenter__(self: _S) -> Awaitable[_S]: ...
91 def __aexit__(
92 self,
93 __exc_type: Optional[Type[BaseException]],
94 __exc_value: Optional[BaseException],
95 __traceback: Optional[TracebackType],
96 ) -> Awaitable[bool]: ...
97
98 if sys.version_info >= (3, 7):
99 @overload
100 def nullcontext(enter_result: _T) -> ContextManager[_T]: ...
101 @overload
102 def nullcontext() -> ContextManager[None]: ...
103