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-39048: Look up __aenter__ before __aexit__ in the async with statement #17609

Merged
merged 5 commits into from
Jan 14, 2020

Conversation

geryogam
Copy link
Contributor

@geryogam geryogam commented Dec 14, 2019

This PR will introduce the following changes:

  • look up the __aenter__ method before the __aexit__ method in the async with statement;
  • add assertions testing that these lookups are performed before executing the body of the async with statement;
  • update the documentation accordingly.

https://bugs.python.org/issue39048

@geryogam geryogam changed the title bop-27100: Reorder the __aenter__ and __aexit__ checks for async with bpo-27100: Reorder the __aenter__ and __aexit__ checks for async with Dec 14, 2019
@geryogam geryogam changed the title bpo-27100: Reorder the __aenter__ and __aexit__ checks for async with bpo-39048: Reorder the __aenter__ and __aexit__ checks for async with Dec 14, 2019
@geryogam geryogam changed the title bpo-39048: Reorder the __aenter__ and __aexit__ checks for async with bpo-39048: Reorder the __aenter__ and __aexit__ method checks for the async with statement Dec 14, 2019
Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

The change itself looks good to me - just a request for another test case to cover the second error handling branch (if we had already had such a test, we would have picked up the refleak in the previous iteration of the code).

We'll also need a NEWS entry.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella
Copy link
Contributor

@maggyero, please address the code review when you get a chance. Thank you!

@geryogam
Copy link
Contributor Author

Sorry @ncoghlan @csabella for the delay, I was on holiday. I am going to address the review today.

@csabella
Copy link
Contributor

@maggyero, thank you. I just wanted to make sure you had seen the review.

@geryogam geryogam changed the title bpo-39048: Reorder the __aenter__ and __aexit__ method checks for the async with statement bpo-39048: Change the lookup order of __aenter__ and __aexit__ in the async with statement Jan 13, 2020
@geryogam geryogam changed the title bpo-39048: Change the lookup order of __aenter__ and __aexit__ in the async with statement bpo-39048: Change the lookup order of __aenter__ and __aexit__ for the async with statement Jan 13, 2020
@geryogam geryogam changed the title bpo-39048: Change the lookup order of __aenter__ and __aexit__ for the async with statement bpo-39048: Change the lookup order of __aenter__ and __aexit__ for async with Jan 13, 2020
@geryogam
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ncoghlan: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from ncoghlan January 13, 2020 14:35
@geryogam geryogam requested a review from ncoghlan January 14, 2020 11:18
@ncoghlan ncoghlan merged commit 1d1b97a into python:master Jan 14, 2020
@ncoghlan
Copy link
Contributor

Thank you for the patch!

@geryogam geryogam deleted the patch-14 branch January 14, 2020 12:08
@geryogam geryogam changed the title bpo-39048: Change the lookup order of __aenter__ and __aexit__ for async with bpo-39048: Look up __aenter__ before __aexit__ in async with Jan 14, 2020
@geryogam geryogam changed the title bpo-39048: Look up __aenter__ before __aexit__ in async with bpo-39048: Look up __aenter__ before __aexit__ in the async with statement Jan 14, 2020
@geryogam
Copy link
Contributor Author

geryogam commented Jan 14, 2020

Thank you for the review @ncoghlan (and @rhettinger)!

@geryogam
Copy link
Contributor Author

@ncoghlan Like for PR #17608, shouldn’t we back port this PR to the 3.8 branch?

@ncoghlan
Copy link
Contributor

No, this one isn't eligible for backport as it's a behavioural change, whereas the previous PR was just a docs update.

@geryogam
Copy link
Contributor Author

Alright @ncoghlan!

shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
…H-17609)

* Reorder the __aenter__ and __aexit__ checks for async with
* Add assertions for async with body being skipped
* Swap __aexit__ and __aenter__ loading in the documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants