aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/contextlib2/py3
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-03-04 21:16:16 +0300
committershadchin <shadchin@yandex-team.com>2024-03-04 21:43:39 +0300
commit74819c4157bd388a7d429c870ea4b343a282dafa (patch)
tree4bff355b03dfb24b14d33581357cc8e624d170fd /contrib/python/contextlib2/py3
parentf64c28a5443395e3a8f27e6f1b15a3507812d2de (diff)
downloadydb-74819c4157bd388a7d429c870ea4b343a282dafa.tar.gz
Extend support pyi files
Сейчас pyi файлы в макросе PY_SRCS используются исключительно в Arcadia плагине для продуктов JB, при сборке эти файлы просто игнорируются. В этом PR добавил шаг, который будет содержимое этих файлов складывать в ресурсы, секция PY_SRCS удобна тем, что позволяет раскладывать pyi файлы с учетом TOP_LEVEL/NAMESPACE, а это необходимо для правильной работы mypy. 3924b0556bc99947e6893cd79e5ce62ec72a18a9
Diffstat (limited to 'contrib/python/contextlib2/py3')
-rw-r--r--contrib/python/contextlib2/py3/contextlib2/__init__.pyi132
1 files changed, 132 insertions, 0 deletions
diff --git a/contrib/python/contextlib2/py3/contextlib2/__init__.pyi b/contrib/python/contextlib2/py3/contextlib2/__init__.pyi
new file mode 100644
index 0000000000..d42c6b05cb
--- /dev/null
+++ b/contrib/python/contextlib2/py3/contextlib2/__init__.pyi
@@ -0,0 +1,132 @@
+# Type hints copied from the typeshed project under the Apache License 2.0
+# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE
+
+import sys
+from types import TracebackType
+from typing import (
+ IO,
+ Any,
+ AsyncContextManager,
+ AsyncIterator,
+ Awaitable,
+ Callable,
+ ContextManager,
+ Iterator,
+ Optional,
+ Type,
+ TypeVar,
+ overload,
+)
+from typing_extensions import ParamSpec, Protocol
+
+# contextlib2 API adaptation notes:
+# * the various 'if True:' guards replace sys.version checks in the original
+# typeshed file (those APIs are available on all supported versions)
+# * deliberately omitted APIs are listed in `dev/mypy.allowlist`
+# (e.g. deprecated experimental APIs that never graduated to the stdlib)
+
+AbstractContextManager = ContextManager
+if True:
+ AbstractAsyncContextManager = AsyncContextManager
+
+_T = TypeVar("_T")
+_T_co = TypeVar("_T_co", covariant=True)
+_T_io = TypeVar("_T_io", bound=Optional[IO[str]])
+_F = TypeVar("_F", bound=Callable[..., Any])
+_P = ParamSpec("_P")
+
+_ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
+_CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc)
+
+class _GeneratorContextManager(ContextManager[_T_co]):
+ def __call__(self, func: _F) -> _F: ...
+
+# type ignore to deal with incomplete ParamSpec support in mypy
+def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore
+
+if True:
+ def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore
+
+class _SupportsClose(Protocol):
+ def close(self) -> object: ...
+
+_SupportsCloseT = TypeVar("_SupportsCloseT", bound=_SupportsClose)
+
+class closing(ContextManager[_SupportsCloseT]):
+ def __init__(self, thing: _SupportsCloseT) -> None: ...
+
+if True:
+ class _SupportsAclose(Protocol):
+ async def aclose(self) -> object: ...
+ _SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
+ class aclosing(AsyncContextManager[_SupportsAcloseT]):
+ def __init__(self, thing: _SupportsAcloseT) -> None: ...
+ _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]])
+ class AsyncContextDecorator:
+ def __call__(self, func: _AF) -> _AF: ...
+
+class suppress(ContextManager[None]):
+ def __init__(self, *exceptions: Type[BaseException]) -> None: ...
+ def __exit__(
+ self, exctype: Optional[Type[BaseException]], excinst: Optional[BaseException], exctb: Optional[TracebackType]
+ ) -> bool: ...
+
+class redirect_stdout(ContextManager[_T_io]):
+ def __init__(self, new_target: _T_io) -> None: ...
+
+class redirect_stderr(ContextManager[_T_io]):
+ def __init__(self, new_target: _T_io) -> None: ...
+
+class ContextDecorator:
+ def __call__(self, func: _F) -> _F: ...
+
+_U = TypeVar("_U", bound=ExitStack)
+
+class ExitStack(ContextManager[ExitStack]):
+ def __init__(self) -> None: ...
+ def enter_context(self, cm: ContextManager[_T]) -> _T: ...
+ def push(self, exit: _CM_EF) -> _CM_EF: ...
+ def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
+ def pop_all(self: _U) -> _U: ...
+ def close(self) -> None: ...
+ def __enter__(self: _U) -> _U: ...
+ def __exit__(
+ self,
+ __exc_type: Optional[Type[BaseException]],
+ __exc_value: Optional[BaseException],
+ __traceback: Optional[TracebackType],
+ ) -> bool: ...
+
+if True:
+ _S = TypeVar("_S", bound=AsyncExitStack)
+
+ _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
+ _CallbackCoroFunc = Callable[..., Awaitable[Any]]
+ _ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc)
+ class AsyncExitStack(AsyncContextManager[AsyncExitStack]):
+ def __init__(self) -> None: ...
+ def enter_context(self, cm: ContextManager[_T]) -> _T: ...
+ def enter_async_context(self, cm: AsyncContextManager[_T]) -> Awaitable[_T]: ...
+ def push(self, exit: _CM_EF) -> _CM_EF: ...
+ def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
+ def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
+ def push_async_callback(self, callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
+ def pop_all(self: _S) -> _S: ...
+ def aclose(self) -> Awaitable[None]: ...
+ def __aenter__(self: _S) -> Awaitable[_S]: ...
+ def __aexit__(
+ self,
+ __exc_type: Optional[Type[BaseException]],
+ __exc_value: Optional[BaseException],
+ __traceback: Optional[TracebackType],
+ ) -> Awaitable[bool]: ...
+
+if True:
+ class nullcontext(AbstractContextManager[_T]):
+ enter_result: _T
+ @overload
+ def __init__(self: nullcontext[None], enter_result: None = ...) -> None: ...
+ @overload
+ def __init__(self: nullcontext[_T], enter_result: _T) -> None: ...
+ def __enter__(self) -> _T: ...
+ def __exit__(self, *exctype: Any) -> bool: ...