mirror of
https://github.com/jazzband/contextlib2.git
synced 2026-03-16 21:50:24 +00:00
Merge pull request #45 from jazzband/typeshed-resync
This commit is contained in:
commit
3feaef8f91
3 changed files with 24 additions and 19 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE
|
# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
from ._typeshed import Self
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import (
|
from typing import (
|
||||||
IO,
|
IO,
|
||||||
|
|
@ -80,16 +81,14 @@ class redirect_stderr(ContextManager[_T_io]):
|
||||||
class ContextDecorator:
|
class ContextDecorator:
|
||||||
def __call__(self, func: _F) -> _F: ...
|
def __call__(self, func: _F) -> _F: ...
|
||||||
|
|
||||||
_U = TypeVar("_U", bound=ExitStack)
|
|
||||||
|
|
||||||
class ExitStack(ContextManager[ExitStack]):
|
class ExitStack(ContextManager[ExitStack]):
|
||||||
def __init__(self) -> None: ...
|
def __init__(self) -> None: ...
|
||||||
def enter_context(self, cm: ContextManager[_T]) -> _T: ...
|
def enter_context(self, cm: ContextManager[_T]) -> _T: ...
|
||||||
def push(self, exit: _CM_EF) -> _CM_EF: ...
|
def push(self, exit: _CM_EF) -> _CM_EF: ...
|
||||||
def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
|
def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
|
||||||
def pop_all(self: _U) -> _U: ...
|
def pop_all(self: Self) -> Self: ...
|
||||||
def close(self) -> None: ...
|
def close(self) -> None: ...
|
||||||
def __enter__(self: _U) -> _U: ...
|
def __enter__(self: Self) -> Self: ...
|
||||||
def __exit__(
|
def __exit__(
|
||||||
self,
|
self,
|
||||||
__exc_type: Optional[Type[BaseException]],
|
__exc_type: Optional[Type[BaseException]],
|
||||||
|
|
@ -98,8 +97,6 @@ class ExitStack(ContextManager[ExitStack]):
|
||||||
) -> bool: ...
|
) -> bool: ...
|
||||||
|
|
||||||
if True:
|
if True:
|
||||||
_S = TypeVar("_S", bound=AsyncExitStack)
|
|
||||||
|
|
||||||
_ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
|
_ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
|
||||||
_CallbackCoroFunc = Callable[..., Awaitable[Any]]
|
_CallbackCoroFunc = Callable[..., Awaitable[Any]]
|
||||||
_ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc)
|
_ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc)
|
||||||
|
|
@ -111,9 +108,9 @@ if True:
|
||||||
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
|
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
|
||||||
def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ...
|
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 push_async_callback(self, callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
|
||||||
def pop_all(self: _S) -> _S: ...
|
def pop_all(self: Self) -> Self: ...
|
||||||
def aclose(self) -> Awaitable[None]: ...
|
def aclose(self) -> Awaitable[None]: ...
|
||||||
def __aenter__(self: _S) -> Awaitable[_S]: ...
|
def __aenter__(self: Self) -> Awaitable[Self]: ...
|
||||||
def __aexit__(
|
def __aexit__(
|
||||||
self,
|
self,
|
||||||
__exc_type: Optional[Type[BaseException]],
|
__exc_type: Optional[Type[BaseException]],
|
||||||
|
|
|
||||||
5
contextlib2/_typeshed.py
Normal file
5
contextlib2/_typeshed.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
from typing import TypeVar # pragma: no cover
|
||||||
|
|
||||||
|
# Use for "self" annotations:
|
||||||
|
# def __enter__(self: Self) -> Self: ...
|
||||||
|
Self = TypeVar("Self") # pragma: no cover
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
--- ../contextlib.pyi 2021-06-29 19:05:46.515307191 +0100
|
--- ../contextlib.pyi 2021-07-16 08:26:16.409945194 +0100
|
||||||
+++ contextlib2/__init__.pyi 2021-06-29 19:15:26.814620184 +0100
|
+++ contextlib2/__init__.pyi 2021-07-20 14:10:49.571136279 +0100
|
||||||
@@ -1,3 +1,6 @@
|
@@ -1,5 +1,8 @@
|
||||||
+# Type hints copied from the typeshed project under the Apache License 2.0
|
+# Type hints copied from the typeshed project under the Apache License 2.0
|
||||||
+# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE
|
+# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE
|
||||||
+
|
+
|
||||||
import sys
|
import sys
|
||||||
|
-from _typeshed import Self
|
||||||
|
+from ._typeshed import Self
|
||||||
from types import TracebackType
|
from types import TracebackType
|
||||||
from typing import (
|
from typing import (
|
||||||
@@ -16,8 +19,14 @@
|
IO,
|
||||||
|
@@ -17,8 +20,14 @@
|
||||||
)
|
)
|
||||||
from typing_extensions import ParamSpec, Protocol
|
from typing_extensions import ParamSpec, Protocol
|
||||||
|
|
||||||
|
|
@ -23,7 +26,7 @@
|
||||||
AbstractAsyncContextManager = AsyncContextManager
|
AbstractAsyncContextManager = AsyncContextManager
|
||||||
|
|
||||||
_T = TypeVar("_T")
|
_T = TypeVar("_T")
|
||||||
@@ -35,7 +44,7 @@
|
@@ -36,7 +45,7 @@
|
||||||
# type ignore to deal with incomplete ParamSpec support in mypy
|
# type ignore to deal with incomplete ParamSpec support in mypy
|
||||||
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore
|
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore
|
||||||
|
|
||||||
|
|
@ -32,7 +35,7 @@
|
||||||
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore
|
def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore
|
||||||
|
|
||||||
class _SupportsClose(Protocol):
|
class _SupportsClose(Protocol):
|
||||||
@@ -46,7 +55,7 @@
|
@@ -47,7 +56,7 @@
|
||||||
class closing(ContextManager[_SupportsCloseT]):
|
class closing(ContextManager[_SupportsCloseT]):
|
||||||
def __init__(self, thing: _SupportsCloseT) -> None: ...
|
def __init__(self, thing: _SupportsCloseT) -> None: ...
|
||||||
|
|
||||||
|
|
@ -41,16 +44,16 @@
|
||||||
class _SupportsAclose(Protocol):
|
class _SupportsAclose(Protocol):
|
||||||
def aclose(self) -> Awaitable[object]: ...
|
def aclose(self) -> Awaitable[object]: ...
|
||||||
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
|
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose)
|
||||||
@@ -88,7 +97,7 @@
|
@@ -87,7 +96,7 @@
|
||||||
__traceback: Optional[TracebackType],
|
__traceback: Optional[TracebackType],
|
||||||
) -> bool: ...
|
) -> bool: ...
|
||||||
|
|
||||||
-if sys.version_info >= (3, 7):
|
-if sys.version_info >= (3, 7):
|
||||||
+if True:
|
+if True:
|
||||||
_S = TypeVar("_S", bound=AsyncExitStack)
|
|
||||||
|
|
||||||
_ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
|
_ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]]
|
||||||
@@ -112,7 +121,8 @@
|
_CallbackCoroFunc = Callable[..., Awaitable[Any]]
|
||||||
|
_ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc)
|
||||||
|
@@ -109,7 +118,8 @@
|
||||||
__traceback: Optional[TracebackType],
|
__traceback: Optional[TracebackType],
|
||||||
) -> Awaitable[bool]: ...
|
) -> Awaitable[bool]: ...
|
||||||
|
|
||||||
|
|
@ -60,7 +63,7 @@
|
||||||
class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]):
|
class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]):
|
||||||
enter_result: _T
|
enter_result: _T
|
||||||
@overload
|
@overload
|
||||||
@@ -123,13 +133,3 @@
|
@@ -120,13 +130,3 @@
|
||||||
def __exit__(self, *exctype: Any) -> None: ...
|
def __exit__(self, *exctype: Any) -> None: ...
|
||||||
async def __aenter__(self) -> _T: ...
|
async def __aenter__(self) -> _T: ...
|
||||||
async def __aexit__(self, *exctype: Any) -> None: ...
|
async def __aexit__(self, *exctype: Any) -> None: ...
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue