-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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-104770: Let generator.close() return value #104771
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
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.
I'm also asking @iritkatriel to review -- I'm not sure if poking at tstate->current_exception
is the right way to access the current exception. Maybe the brand new PyPyErr_GetRaisedException()
is the API to use? (Then you don't even need to get the tstate).
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. In the docs, I made the wording of the "returns return value" situation sound as natural as I could, but it might need more polishing. I didn't know about |
Thanks for making the requested changes! @gvanrossum: please review the changes made to this pull request. |
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 |
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Thanks @iritkatriel, that is much better. I have made the requested changes; please review again. |
Thanks for making the requested changes! @gvanrossum, @iritkatriel: please review the changes made to this pull request. |
I'll leave the rest of the review to Irit. |
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.
Code looks fine, a couple of comments on documentation.
Misc/NEWS.d/next/Core and Builtins/2023-05-23-00-36-02.gh-issue-104770.poSkyY.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
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.
Fantastic! I will merge now.
Thanks again Irit and Guido for your help and patience! |
This changeset alters
generator.close()
to return the value of aStopIteration
it encounters. Conceptually, the change is simple: instead of lumpingStopIteration
in withGeneratorExit
and ignoring it, the exception is handled specially and its value returned.Practically, handling the exception is a little awkward because no high-level API exists (afaict) to retrieve the value of a
StopIteration
. I would be happy for any pointers on how to handle this better, if possible.📚 Documentation preview 📚: https://cpython-previews--104771.org.readthedocs.build/