massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / coc-python-data / languageServer.0.5.59 / Typeshed / stdlib / 2and3 / contextlib.pyi
1 # Stubs for contextlib\r
2 \r
3 from typing import (\r
4     Any, Callable, Generator, IO, Iterable, Iterator, Optional, Type,\r
5     Generic, TypeVar\r
6 )\r
7 from types import TracebackType\r
8 import sys\r
9 # Aliased here for backwards compatibility; TODO eventually remove this\r
10 from typing import ContextManager as ContextManager\r
11 \r
12 if sys.version_info >= (3, 5):\r
13     from typing import AsyncContextManager, AsyncIterator\r
14 \r
15 if sys.version_info >= (3, 6):\r
16     from typing import ContextManager as AbstractContextManager\r
17 if sys.version_info >= (3, 7):\r
18     from typing import AsyncContextManager as AbstractAsyncContextManager\r
19 \r
20 _T = TypeVar('_T')\r
21 \r
22 _ExitFunc = Callable[[Optional[Type[BaseException]],\r
23                       Optional[BaseException],\r
24                       Optional[TracebackType]], bool]\r
25 _CM_EF = TypeVar('_CM_EF', ContextManager, _ExitFunc)\r
26 \r
27 if sys.version_info >= (3, 2):\r
28     class GeneratorContextManager(ContextManager[_T], Generic[_T]):\r
29         def __call__(self, func: Callable[..., _T]) -> Callable[..., _T]: ...\r
30     def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., GeneratorContextManager[_T]]: ...\r
31 else:\r
32     def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...\r
33 \r
34 if sys.version_info >= (3, 7):\r
35     def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ...\r
36 \r
37 if sys.version_info < (3,):\r
38     def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...\r
39 \r
40 class closing(ContextManager[_T], Generic[_T]):\r
41     def __init__(self, thing: _T) -> None: ...\r
42 \r
43 if sys.version_info >= (3, 4):\r
44     class suppress(ContextManager[None]):\r
45         def __init__(self, *exceptions: Type[BaseException]) -> None: ...\r
46 \r
47     class redirect_stdout(ContextManager[None]):\r
48         def __init__(self, new_target: IO[str]) -> None: ...\r
49 \r
50 if sys.version_info >= (3, 5):\r
51     class redirect_stderr(ContextManager[None]):\r
52         def __init__(self, new_target: IO[str]) -> None: ...\r
53 \r
54 if sys.version_info >= (3,):\r
55     class ContextDecorator:\r
56         def __call__(self, func: Callable[..., None]) -> Callable[..., ContextManager[None]]: ...\r
57 \r
58     _U = TypeVar('_U', bound='ExitStack')\r
59 \r
60     class ExitStack(ContextManager[ExitStack]):\r
61         def __init__(self) -> None: ...\r
62         def enter_context(self, cm: ContextManager[_T]) -> _T: ...\r
63         def push(self, exit: _CM_EF) -> _CM_EF: ...\r
64         def callback(self, callback: Callable[..., Any],\r
65                      *args: Any, **kwds: Any) -> Callable[..., Any]: ...\r
66         def pop_all(self: _U) -> _U: ...\r
67         def close(self) -> None: ...\r
68         def __enter__(self: _U) -> _U: ...\r
69 \r
70 if sys.version_info >= (3, 7):\r
71     from typing import Awaitable\r
72 \r
73     _S = TypeVar('_S', bound='AsyncExitStack')\r
74 \r
75     _ExitCoroFunc = Callable[[Optional[Type[BaseException]],\r
76                               Optional[BaseException],\r
77                               Optional[TracebackType]], Awaitable[bool]]\r
78     _CallbackCoroFunc = Callable[..., Awaitable[Any]]\r
79     _ACM_EF = TypeVar('_ACM_EF', AsyncContextManager, _ExitCoroFunc)\r
80 \r
81     class AsyncExitStack(AsyncContextManager[AsyncExitStack]):\r
82         def __init__(self) -> None: ...\r
83         def enter_context(self, cm: ContextManager[_T]) -> _T: ...\r
84         def enter_async_context(self, cm: AsyncContextManager[_T]) -> Awaitable[_T]: ...\r
85         def push(self, exit: _CM_EF) -> _CM_EF: ...\r
86         def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...\r
87         def callback(self, callback: Callable[..., Any],\r
88                      *args: Any, **kwds: Any) -> Callable[..., Any]: ...\r
89         def push_async_callback(self, callback: _CallbackCoroFunc,\r
90                                 *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...\r
91         def pop_all(self: _S) -> _S: ...\r
92         def aclose(self) -> Awaitable[None]: ...\r
93         def __aenter__(self: _S) -> Awaitable[_S]: ...\r