FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-135110: Fix misleading generator.close() documentation by cdenihan · Pull Request #135152 · python/cpython · GitHub

Repository navigation

gh-135110: Fix misleading generator.close() documentation - #135152

Merged
ZeroIntensity merged 6 commits into
python:mainfrom
cdenihan:fix-generator-close-docs
Jun 26, 2025
Merged

ZeroIntensity merged 6 commits into
python:mainfrom
cdenihan:fix-generator-close-docs

Conversation

cdenihan commented Jun 4, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

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:

  • The method sends the GeneratorExit exception to the generator internally
  • The method returns None to the caller
  • The method does not raise the exception to the caller

Solution

Changed 'raises' to 'sends' in both documentation files for accuracy and consistency:

  1. Doc/reference/expressions.rst (line 628-629):

    • Before: 'Raises a GeneratorExit at the point where the generator function was paused'
    • After: 'Sends a GeneratorExit exception to the generator at the point where the generator function was paused'
  2. Doc/howto/functional.rst (line 605):

    • Before: 'raises a GeneratorExit exception inside the'
    • After: 'sends a GeneratorExit exception inside the'

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/

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 #135110

python-cla-bot Bot commented Jun 4, 2025 •
edited
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Jun 4, 2025
github-project-automation Bot moved this to Todo in Docs PRs Jun 4, 2025
cdenihan changed the title Fix misleading generator.close() documentation gh-135110: Fix misleading generator.close() documentation Jun 4, 2025

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)?

cdenihan added 2 commits June 20, 2025 11:44
Replace 'sends' with 'raises' and clarify that close() is equivalent to throw(GeneratorExit). This makes the documentation clearer and avoids confusion with generator.send().
cdenihan requested a review from ZeroIntensity June 20, 2025 15:57
Comment thread Doc/howto/functional.rst Outdated
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>

Copy link
Copy Markdown
Member

It looks like the CLA got screwed up.

cdenihan commented Jun 20, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Just signed it again, should be all good now.

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks!

Copy link
Copy Markdown

Thanks @cdenihan for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 26, 2025
…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>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 26, 2025
…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>

bedevere-app Bot commented Jun 26, 2025

Copy link
Copy Markdown

GH-135985 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 26, 2025

bedevere-app Bot commented Jun 26, 2025

Copy link
Copy Markdown

GH-135986 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 26, 2025
ZeroIntensity pushed a commit that referenced this pull request Jun 26, 2025
…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>
ZeroIntensity pushed a commit that referenced this pull request Jun 26, 2025
…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>
cdenihan deleted the fix-generator-close-docs branch June 26, 2025 15:19
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
…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.
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…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.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…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.
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

generator.close() never raises GeneratorExit

4 participants


Back | FazBrowse Home | New Git URL