massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / contextlib.pyi
1 import sys
2 from _typeshed import Self, StrOrBytesPath
3 from types import TracebackType
4 from typing import (
5     IO,
6     Any,
7     AsyncIterator,
8     Awaitable,
9     Callable,
10     ContextManager,
11     Generic,
12     Iterator,
13     Optional,
14     Type,
15     TypeVar,
16     overload,
17 )
18 from typing_extensions import ParamSpec, Protocol
19
20 AbstractContextManager = ContextManager
21 if sys.version_info >= (3, 7):
22     from typing import AsyncContextManager
23
24     AbstractAsyncContextManager = AsyncContextManager
25
26 _T = TypeVar("_T")
27 _T_co = TypeVar("_T_co", covariant=True)
28 _T_io = TypeVar("_T_io", bound=Optional[IO[str]])
29 _F = TypeVar("_F", bound=Callable[..., Any])
30 _P = ParamSpec("_P")
31
32 _ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
33 _CM_EF = TypeVar("_CM_EF", AbstractContextManager[Any], _ExitFunc)
34
35 class _GeneratorContextManager(AbstractContextManager[_T_co]):
36     def __call__(self, func: _F) -> _F: ...
37
38 # type ignore to deal with incomplete ParamSpec support in mypy
39 def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ...  # type: ignore
40
41 if sys.version_info >= (3, 7):
42     def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AbstractAsyncContextManager[_T]]: ...  # type: ignore
43
44 class _SupportsClose(Protocol):
45     def close(self) -> object: ...
46
47 _SupportsCloseT = TypeVar("_SupportsCloseT", bound=_SupportsClose)
48
49 class closing(AbstractContextManager[_SupportsCloseT]):
50     def __init__(self, thing: _SupportsCloseT) -> None: ...
51
52 if sys.version_info >= (3, 10):
53     class _SupportsAclose(Protocol):
54         def aclose(self) -> Awaitable[object]: ...
55     _SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
56     class aclosing(AbstractAsyncContextManager[_SupportsAcloseT]):
57         def __init__(self, thing: _SupportsAcloseT) -> None: ...
58     _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]])
59     class AsyncContextDecorator:
60         def __call__(self, func: _AF) -> _AF: ...
61
62 class suppress(AbstractContextManager[None]):
63     def __init__(self, *exceptions: Type[BaseException]) -> None: ...
64     def __exit__(
65         self, exctype: Type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
66     ) -> bool: ...
67
68 class redirect_stdout(AbstractContextManager[_T_io]):
69     def __init__(self, new_target: _T_io) -> None: ...
70
71 class redirect_stderr(AbstractContextManager[_T_io]):
72     def __init__(self, new_target: _T_io) -> None: ...
73
74 class ContextDecorator:
75     def __call__(self, func: _F) -> _F: ...
76
77 class ExitStack(AbstractContextManager[ExitStack]):
78     def __init__(self) -> None: ...
79     def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
80     def push(self, exit: _CM_EF) -> _CM_EF: ...
81     def callback(self, __callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
82     def pop_all(self: Self) -> Self: ...
83     def close(self) -> None: ...
84     def __enter__(self: Self) -> Self: ...
85     def __exit__(
86         self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
87     ) -> bool: ...
88
89 if sys.version_info >= (3, 7):
90     _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
91     _CallbackCoroFunc = Callable[..., Awaitable[Any]]
92     _ACM_EF = TypeVar("_ACM_EF", AbstractAsyncContextManager[Any], _ExitCoroFunc)
93     class AsyncExitStack(AbstractAsyncContextManager[AsyncExitStack]):
94         def __init__(self) -> None: ...
95         def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ...
96         def enter_async_context(self, cm: AbstractAsyncContextManager[_T]) -> Awaitable[_T]: ...
97         def push(self, exit: _CM_EF) -> _CM_EF: ...
98         def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
99         def callback(self, __callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
100         def push_async_callback(self, __callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
101         def pop_all(self: Self) -> Self: ...
102         def aclose(self) -> Awaitable[None]: ...
103         def __aenter__(self: Self) -> Awaitable[Self]: ...
104         def __aexit__(
105             self, __exc_type: Type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None
106         ) -> Awaitable[bool]: ...
107
108 if sys.version_info >= (3, 10):
109     class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]):
110         enter_result: _T
111         @overload
112         def __init__(self: nullcontext[None], enter_result: None = ...) -> None: ...
113         @overload
114         def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
115         def __enter__(self) -> _T: ...
116         def __exit__(self, *exctype: Any) -> None: ...
117         async def __aenter__(self) -> _T: ...
118         async def __aexit__(self, *exctype: Any) -> None: ...
119
120 elif sys.version_info >= (3, 7):
121     class nullcontext(AbstractContextManager[_T]):
122         enter_result: _T
123         @overload
124         def __init__(self: nullcontext[None], enter_result: None = ...) -> None: ...
125         @overload
126         def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
127         def __enter__(self) -> _T: ...
128         def __exit__(self, *exctype: Any) -> None: ...
129
130 if sys.version_info >= (3, 11):
131     _T_fd_or_any_path = TypeVar("_T_fd_or_any_path", bound=int | StrOrBytesPath)
132     class chdir(AbstractContextManager[None], Generic[_T_fd_or_any_path]):
133         path: _T_fd_or_any_path
134         def __init__(self, path: _T_fd_or_any_path) -> None: ...
135         def __enter__(self) -> None: ...
136         def __exit__(self, *excinfo: object) -> None: ...