8000 Add stub for AsyncExitContext added by bpo-29302. by Kentzo · Pull Request #1876 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Add stub for AsyncExitContext added by bpo-29302. #1876

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 5 commits into from
Feb 17, 2018
Merged
Changes from 1 commit
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
Next Next commit
Add stub for AsyncExitContext added by bpo-29302.
  • Loading branch information
Kentzo committed Feb 12, 2018
commit a14d125ee03beb23ce10ba4c0ecc328ff8e450f6
26 changes: 26 additions & 0 deletions stdlib/2and3/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,29 @@ if sys.version_info >= (3,):
def pop_all(self) -> ExitStack: ...
def close(self) -> None: ...
def __enter__(self: _U) -> _U: ...

if sys.version_info >= (3, 7):
from asyncio.futures import Future
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use typing.Awaitable instead of Future?

Copy link
Contributor Author
@Kentzo Kentzo Feb 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at stubs for asyncio.tasks as an example.

On the second look I agree, Awaitable should be used instead.


_U = TypeVar('_U', bound='AsyncExitStack')

_ExitCoroFunc = Callable[[Optional[Type[BaseException]],
Optional[BaseException],
Optional[TracebackType]], Future[bool]]
_CallbackCoroFunc = Callable[..., Future[None]]
_ACM_EF = TypeVar('_ACM_EF', AsyncContextManager, _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]) -> Future[_T]: ...
def push(self, exit: _CM_EF) -> _CM_EF: ...
def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ...
def callback(self, callback: Callable[..., None],
*args: Any, **kwds: Any) -> Callable[..., None]: ...
def push_async_callback(self, callback: _CallbackCoroFunc,
*args: Any, **kwds: Any) -> _CallbackCoroFunc: ...
def pop_all(self) -> ExitStack: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return AsyncExitStack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think it should be implemented as __enter__ / __aenter__: pop_all instantiates type(self).

Probably that should also be fixed for ExitStack.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Would you mind fixing it there too while you're at it?

def aclose(self) -> Future[None]: ...
def __enter__(self: _U) -> _U: ...
def __aenter__(self: _U) -> Future[_U]: ...
0