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

gh-118473: Fix set_asyncgen_hooks not to be partially set when arguments are invalid #118474

Merged
merged 3 commits into from
May 7, 2024

Conversation

youknowone
Copy link
Contributor

@youknowone youknowone commented May 1, 2024

@youknowone youknowone changed the title gh-118473: Fix set_asyncgen_hooks not to allow partial setup gh-118473: Fix set_asyncgen_hooks not to be partially set when arguments are invalid May 1, 2024
@gvanrossum
Copy link
Member

I am starting to review. Please do not force push any more -- you can add new commits, and we will squash them when we merge the code.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I'm sorry, I don't like how you separated the audit calls from the setter functions, since it's conceivable that other (internal) code might call them, and the changes should always be audited.

I think a better refactoring would be to save the current finalizer hook and if setting the firstiter hook fails, restore the original finalizer. It still makes sense of course to do both callable checks before making any of the setter calls.

(Note that in your current PR there is a possible scenario where the second audit hook fails, no setters are called, but the first audit hook has already been called.)

Also, CC @zooba.

@@ -0,0 +1 @@
Fix set_asyncgen_hooks not to be partially set when raising TypeError
Copy link
Member

Choose a reason for hiding this comment

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

Please make this proper ReST markup with links to the code for set_asyncgen_hooks and TypeError, and end the sentence with a period. (I can help with the markup but consulting other news files should give ample examples.)

@bedevere-app
Copy link

bedevere-app bot commented May 1, 2024

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.

@youknowone
Copy link
Contributor Author

@gvanrossum Thank you for the guide!

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented May 2, 2024

Thanks for making the requested changes!

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

@bedevere-app bedevere-app bot requested a review from gvanrossum May 2, 2024 03:02
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM. I will merge this now, so it will make it into beta 1. Congrats!

@gvanrossum gvanrossum merged commit 8d8275b into python:main May 7, 2024
38 of 40 checks passed
@gvanrossum
Copy link
Member

@youknowone Do you think this should be backported to Python 3.12? It's a pure bugfix, so I think it could be.

@youknowone youknowone deleted the gh-118473 branch May 7, 2024 07:09
@youknowone
Copy link
Contributor Author

@gvanrossum No opinion about it. I found this bug not by running code, but by watching CPython source code. It is hard to imagine real world code make a try-except block for sys.set_asyncgen_hooks.

@gvanrossum
Copy link
Member

Then let's not backport.

SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
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.

None yet

2 participants