mirror of
https://github.com/python/cpython.git
synced 2025-07-07 11:25:30 +00:00
gh-135110: Fix misleading generator.close()
documentation (GH-135152)
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
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 commit is contained in:
parent
fb9e292919
commit
0d76dccc3b
2 changed files with 5 additions and 3 deletions
|
@ -602,7 +602,7 @@ generators:
|
|||
raise an exception inside the generator; the exception is raised by the
|
||||
``yield`` expression where the generator's execution is paused.
|
||||
|
||||
* :meth:`~generator.close` raises a :exc:`GeneratorExit` exception inside the
|
||||
* :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the
|
||||
generator to terminate the iteration. On receiving this exception, the
|
||||
generator's code must either raise :exc:`GeneratorExit` or
|
||||
:exc:`StopIteration`; catching the exception and doing anything else is
|
||||
|
|
|
@ -625,8 +625,10 @@ is already executing raises a :exc:`ValueError` exception.
|
|||
|
||||
.. method:: generator.close()
|
||||
|
||||
Raises a :exc:`GeneratorExit` at the point where the generator function was
|
||||
paused. If the generator function catches the exception and returns a
|
||||
Raises a :exc:`GeneratorExit` exception at the point where the generator
|
||||
function was paused (equivalent to calling ``throw(GeneratorExit)``).
|
||||
The exception is raised by the yield expression where the generator was paused.
|
||||
If the generator function catches the exception and returns a
|
||||
value, this value is returned from :meth:`close`. If the generator function
|
||||
is already closed, or raises :exc:`GeneratorExit` (by not catching the
|
||||
exception), :meth:`close` returns :const:`None`. If the generator yields a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue