-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
bpo-44471: Change error type for bad objects in ExitStack.enter_context() #26820
bpo-44471: Change error type for bad objects in ExitStack.enter_context() #26820
Conversation
…xt() A TypeError is now raised instead of an AttributeError in ExitStack.enter_context() and AsyncExitStack.enter_async_context() for objects which do not support the context manager or asynchronous context manager protocols correspondingly.
@@ -536,6 +556,18 @@ async def suppress_exc(*exc_details): | |||
self.assertIsInstance(inner_exc, ValueError) | |||
self.assertIsInstance(inner_exc.__context__, ZeroDivisionError) | |||
|
|||
@_async_test | |||
async def test_instance_bypass_async(self): |
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.
What is this test doing?
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.
It is a copy of similar test for synchronous context managers (test_instance_bypass
), but for asynchronous context managers. It tests that special methods are looked up in a class, not in an instance. So merely setting __aenter__
and __aexit__
as instance attributes does not make a context manager. enter_async_context()
fails with relevant message, and push_async_exit()
treats argument as a callable, not context manager.
This was merged with travis and azure failing to build the doc due to trailing whitespaces:
why? (It cause other PR to fail due to this now) |
Thank you for fixing this @JulienPalard. |
You're welcome, I tried to fix it before it impacted much PRs (only #24903 got impacted temporarily). |
A TypeError is now raised instead of an AttributeError in
ExitStack.enter_context() and AsyncExitStack.enter_async_context()
for objects which do not support the context manager or
asynchronous context manager protocols correspondingly.
https://bugs.python.org/issue44471