mirror of
https://github.com/jazzband/contextlib2.git
synced 2026-03-17 06:00:23 +00:00
79 lines
3 KiB
Diff
79 lines
3 KiB
Diff
--- ../contextlib.pyi 2021-07-16 08:26:16.409945194 +0100
|
|
+++ contextlib2/__init__.pyi 2021-07-20 14:10:49.571136279 +0100
|
|
@@ -1,5 +1,8 @@
|
|
+# Type hints copied from the typeshed project under the Apache License 2.0
|
|
+# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE
|
|
+
|
|
import sys
|
|
-from _typeshed import Self
|
|
+from ._typeshed import Self
|
|
from types import TracebackType
|
|
from typing import (
|
|
IO,
|
|
@@ -17,8 +20,14 @@
|
|
)
|
|
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 sys.version_info >= (3, 7):
|
|
+if True:
|
|
AbstractAsyncContextManager = AsyncContextManager
|
|
|
|
_T = TypeVar("_T")
|
|
@@ -36,7 +45,7 @@
|
|
# type ignore to deal with incomplete ParamSpec support in mypy
|
|
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore
|
|
|
|
-if sys.version_info >= (3, 7):
|
|
+if True:
|
|
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore
|
|
|
|
class _SupportsClose(Protocol):
|
|
@@ -47,7 +56,7 @@
|
|
class closing(ContextManager[_SupportsCloseT]):
|
|
def __init__(self, thing: _SupportsCloseT) -> None: ...
|
|
|
|
-if sys.version_info >= (3, 10):
|
|
+if True:
|
|
class _SupportsAclose(Protocol):
|
|
def aclose(self) -> Awaitable[object]: ...
|
|
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
|
|
@@ -87,7 +96,7 @@
|
|
__traceback: Optional[TracebackType],
|
|
) -> bool: ...
|
|
|
|
-if sys.version_info >= (3, 7):
|
|
+if True:
|
|
_ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
|
|
_CallbackCoroFunc = Callable[..., Awaitable[Any]]
|
|
_ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc)
|
|
@@ -109,7 +118,8 @@
|
|
__traceback: Optional[TracebackType],
|
|
) -> Awaitable[bool]: ...
|
|
|
|
-if sys.version_info >= (3, 10):
|
|
+
|
|
+if True:
|
|
class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]):
|
|
enter_result: _T
|
|
@overload
|
|
@@ -120,13 +130,3 @@
|
|
def __exit__(self, *exctype: Any) -> None: ...
|
|
async def __aenter__(self) -> _T: ...
|
|
async def __aexit__(self, *exctype: Any) -> None: ...
|
|
-
|
|
-elif sys.version_info >= (3, 7):
|
|
- 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) -> None: ...
|