-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
stdlib/2and3/contextlib.pyi
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
stdlib/2and3/contextlib.pyi
Outdated
*args: Any, **kwds: Any) -> Callable[..., None]: ... | ||
def push_async_callback(self, callback: _CallbackCoroFunc, | ||
*args: Any, **kwds: Any) -> _CallbackCoroFunc: ... | ||
def pop_all(self) -> ExitStack: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should return AsyncExitStack.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
stdlib/2and3/contextlib.pyi
Outdated
def pop_all(self) -> ExitStack: ... | ||
def aclose(self) -> Awaitable[None]: ... | ||
def __enter__(self: _U) -> _U: ... | ||
def __aenter__(self: _U) -> Awaitable[_U]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you not need __exit__
and __aexit__
? I suppose the base class provides those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base class implementations should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that's true for __aexit__
but not __exit__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you mean that's because AsyncContextManager
does not inherit from ContextManager
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nvm. There is no __enter__
for AsyncExitStack
.
@JelleZijlstra Should I squash into 2 commits: one for AsyncExitStack and one for ExitStack's bugfix? |
No, that's fine. I'll squash when I merge (which I will do as soon as CI passes). |
Stub for changes added to Python 3.7 in python/cpython#4790.