-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135110: Fix misleading generator.close() documentation #135152
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
Conversation
The documentation incorrectly stated that generator.close() 'raises' a GeneratorExit exception. This was misleading because the method doesn't raise the exception to the caller - it sends the exception internally to the generator and returns None. Changed 'raises' to 'sends' in both Doc/reference/expressions.rst and Doc/howto/functional.rst for consistency and accuracy. Fixes python#135110
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 a little worried about the use of the word "send" here, especially considering generator.send()
is a thing. I think "raises" is fine, we should just make it clearer that the actual yield
expressions are what raise. Maybe we could say that close()
is equivalent to throw(GeneratorExit)
?
Replace 'sends' with 'raises' and clarify that close() is equivalent to throw(GeneratorExit). This makes the documentation clearer and avoids confusion with generator.send().
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
It looks like the CLA got screwed up. |
Just signed it again, should be all good now. |
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.
Thanks!
Thanks @cdenihan for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…thonGH-135152) The documentation incorrectly stated that generator.close() 'raises' a GeneratorExit exception. This was misleading because the method doesn't raise the exception to the caller - it sends the exception internally to the generator and returns None. (cherry picked from commit 0d76dcc) Co-authored-by: Connor Denihan <188690869+cdenihan@users.noreply.github.com>
…thonGH-135152) The documentation incorrectly stated that generator.close() 'raises' a GeneratorExit exception. This was misleading because the method doesn't raise the exception to the caller - it sends the exception internally to the generator and returns None. (cherry picked from commit 0d76dcc) Co-authored-by: Connor Denihan <188690869+cdenihan@users.noreply.github.com>
GH-135985 is a backport of this pull request to the 3.14 branch. |
GH-135986 is a backport of this pull request to the 3.13 branch. |
…H-135152) (GH-135986) gh-135110: Fix misleading `generator.close()` documentation (GH-135152) The documentation incorrectly stated that generator.close() 'raises' a GeneratorExit exception. This was misleading because the method doesn't raise the exception to the caller - it sends the exception internally to the generator and returns None. (cherry picked from commit 0d76dcc) Co-authored-by: Connor Denihan <188690869+cdenihan@users.noreply.github.com>
…H-135152) (GH-135985) gh-135110: Fix misleading `generator.close()` documentation (GH-135152) The documentation incorrectly stated that generator.close() 'raises' a GeneratorExit exception. This was misleading because the method doesn't raise the exception to the caller - it sends the exception internally to the generator and returns None. (cherry picked from commit 0d76dcc) Co-authored-by: Connor Denihan <188690869+cdenihan@users.noreply.github.com>
This PR fixes the misleading documentation for generator.close() that incorrectly stated the method 'raises a GeneratorExit' to the caller.
Problem
The current documentation in both Doc/reference/expressions.rst and Doc/howto/functional.rst states that generator.close() 'raises a GeneratorExit' which is misleading because:
Solution
Changed 'raises' to 'sends' in both documentation files for accuracy and consistency:
Doc/reference/expressions.rst (line 628-629):
Doc/howto/functional.rst (line 605):
Testing
The behavior described in the fixed documentation can be verified by the examples in the original issue report, which show that generator.close() always returns None.
Fixes #135110
📚 Documentation preview 📚: https://cpython-previews--135152.org.readthedocs.build/
generator.close()
never raisesGeneratorExit
#135110