-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from ncoghlan/issue-33-add-type-hinting-support
Issue #33: convert to package and include typeshed type hints
- Loading branch information
Showing
11 changed files
with
242 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[![Jazzband](https://jazzband.co/static/img/jazzband.svg)](https://jazzband.co/) | ||
|
||
This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) and follow the [guidelines](https://jazzband.co/about/guidelines). | ||
This is a [Jazzband](https://jazzband.co/) project. By contributing you agree | ||
to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) | ||
and follow the [guidelines](https://jazzband.co/about/guidelines). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
include *.py *.txt *.rst *.md *.ini MANIFEST.in | ||
recursive-include dev test docs *.rst *.py make.bat Makefile | ||
include *.py *.cfg *.txt *.rst *.md *.ini MANIFEST.in | ||
recursive-include contextlib2 *.py *.pyi py.typed | ||
recursive-include docs *.rst *.py make.bat Makefile | ||
recursive-include test *.py | ||
recursive-include dev *.patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# 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 | ||
|
||
# Note: the various 'if True:' guards replace sys.version checks in the | ||
# original typeshed file that don't apply to the contextlib2 backport API | ||
|
||
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: | ||
@overload | ||
def nullcontext(enter_result: _T) -> ContextManager[_T]: ... | ||
@overload | ||
def nullcontext() -> ContextManager[None]: ... |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- ../contextlib.pyi 2021-06-26 21:36:16.491964153 +1000 | ||
+++ contextlib2/__init__.pyi 2021-06-26 21:41:08.109598690 +1000 | ||
@@ -1,3 +1,6 @@ | ||
+# 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 ( | ||
@@ -16,8 +19,11 @@ | ||
) | ||
from typing_extensions import ParamSpec, Protocol | ||
|
||
+# Note: the various 'if True:' guards replace sys.version checks in the | ||
+# original typeshed file that don't apply to the contextlib2 backport API | ||
+ | ||
AbstractContextManager = ContextManager | ||
-if sys.version_info >= (3, 7): | ||
+if True: | ||
AbstractAsyncContextManager = AsyncContextManager | ||
|
||
_T = TypeVar("_T") | ||
@@ -35,7 +41,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): | ||
@@ -46,7 +52,7 @@ | ||
class closing(ContextManager[_SupportsCloseT]): | ||
def __init__(self, thing: _SupportsCloseT) -> None: ... | ||
|
||
-if sys.version_info >= (3, 10): | ||
+if True: | ||
class _SupportsAclose(Protocol): | ||
async def aclose(self) -> object: ... | ||
_SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose) | ||
@@ -88,7 +94,7 @@ | ||
__traceback: Optional[TracebackType], | ||
) -> bool: ... | ||
|
||
-if sys.version_info >= (3, 7): | ||
+if True: | ||
_S = TypeVar("_S", bound=AsyncExitStack) | ||
|
||
_ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]] | ||
@@ -112,7 +118,7 @@ | ||
__traceback: Optional[TracebackType], | ||
) -> Awaitable[bool]: ... | ||
|
||
-if sys.version_info >= (3, 7): | ||
+if True: | ||
@overload | ||
def nullcontext(enter_result: _T) -> ContextManager[_T]: ... | ||
@overload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters