bpo-44471: Change error type for bad objects in ExitStack.enter_context()#26820
Merged
serhiy-storchaka merged 2 commits intopython:mainfrom Jun 29, 2021
Merged
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.
iritkatriel
reviewed
Jun 21, 2021
iritkatriel
reviewed
Jun 21, 2021
| self.assertIsInstance(inner_exc.__context__, ZeroDivisionError) | ||
|
|
||
| @_async_test | ||
| async def test_instance_bypass_async(self): |
Member
Author
There was a problem hiding this comment.
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.
iritkatriel
approved these changes
Jun 21, 2021
Member
|
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) |
Member
Author
|
Thank you for fixing this @JulienPalard. |
Member
|
You're welcome, I tried to fix it before it impacted much PRs (only #24903 got impacted temporarily). |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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