Skip to content
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

Merged
merged 2 commits into from
Jun 29, 2021

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jun 21, 2021

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

…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):
Copy link
Member

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?

Copy link
Member Author

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.

@serhiy-storchaka serhiy-storchaka merged commit 6cb145d into python:main Jun 29, 2021
@serhiy-storchaka serhiy-storchaka deleted the contextlib-type-error branch June 29, 2021 08:28
@JulienPalard
Copy link
Member

This was merged with travis and azure failing to build the doc due to trailing whitespaces:

$ (cd Doc; python3.6 tools/rstlint.py -i tools -i ./venv -i README.rst)
[1] whatsnew/3.11.rst:79: trailing whitespace
[1] whatsnew/3.11.rst:85: trailing whitespace
[1] whatsnew/3.11.rst:87: trailing whitespace
3 problems with severity 1 found.

why? (It cause other PR to fail due to this now)

@serhiy-storchaka
Copy link
Member Author

Thank you for fixing this @JulienPalard.

@JulienPalard
Copy link
Member

You're welcome, I tried to fix it before it impacted much PRs (only #24903 got impacted temporarily).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants