-
-
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
base: main
Are you sure you want to change the base?
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 <[email protected]>
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!
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