Skip to content

add typing.AsyncContextManager and contextlib.asynccontextmanager #1432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stdlib/2and3/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import sys
# Aliased here for backwards compatibility; TODO eventually remove this
from typing import ContextManager as ContextManager

if sys.version_info >= (3, 5):
from typing import AsyncContextManager, AsyncIterator

if sys.version_info >= (3, 6):
from typing import ContextManager as AbstractContextManager

Expand All @@ -26,6 +29,9 @@ if sys.version_info >= (3, 2):
else:
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...

if sys.version_info >= (3, 7):
def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ...

if sys.version_info < (3,):
def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...

Expand Down
7 changes: 7 additions & 0 deletions stdlib/3/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ class ContextManager(Generic[_T_co]):
exc_value: Optional[BaseException],
traceback: Optional[TracebackType]) -> Optional[bool]: ...

if sys.version_info >= (3, 5):
class AsyncContextManager(Generic[_T_co]):
def __aenter__(self) -> Awaitable[_T_co]: ...
def __aexit__(self, exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType]) -> Awaitable[Optional[bool]]: ...

class Mapping(_Collection[_KT], Generic[_KT, _VT_co]):
# TODO: We wish the key type could also be covariant, but that doesn't work,
# see discussion in https: //github.com/python/typing/pull/273.
Expand Down