summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorDave Goncalves <davegoncalves@gmail.com>2022-03-31 13:56:48 (GMT)
committerGitHub <noreply@github.com>2022-03-31 13:56:48 (GMT)
commit8be7c2bc5ad5e295f0f855bb31db412eef2c7c92 (patch)
tree959b21391f252bd6a4ac2935b4035007ed52bdb4 /Doc/reference
parenta00518d9ad9a8f408a9699191019d75dd8406c32 (diff)
downloadcpython-8be7c2bc5ad5e295f0f855bb31db412eef2c7c92.zip
cpython-8be7c2bc5ad5e295f0f855bb31db412eef2c7c92.tar.gz
cpython-8be7c2bc5ad5e295f0f855bb31db412eef2c7c92.tar.bz2
bpo-14911: Corrected generator.throw() documentation (GH-32207)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/datamodel.rst3
-rw-r--r--Doc/reference/expressions.rst17
2 files changed, 17 insertions, 3 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 804332f..8ac9a8c 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -2984,7 +2984,8 @@ generators, coroutines do not directly support iteration.
:exc:`StopIteration`, or other exception) is the same as when
iterating over the :meth:`__await__` return value, described above.
-.. method:: coroutine.throw(type[, value[, traceback]])
+.. method:: coroutine.throw(value)
+ coroutine.throw(type[, value[, traceback]])
Raises the specified exception in the coroutine. This method delegates
to the :meth:`~generator.throw` method of the iterator that caused
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index bb6d1dc..b914c48 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -561,14 +561,27 @@ is already executing raises a :exc:`ValueError` exception.
could receive the value.
-.. method:: generator.throw(type[, value[, traceback]])
+.. method:: generator.throw(value)
+ generator.throw(type[, value[, traceback]])
- Raises an exception of type ``type`` at the point where the generator was paused,
+ Raises an exception at the point where the generator was paused,
and returns the next value yielded by the generator function. If the generator
exits without yielding another value, a :exc:`StopIteration` exception is
raised. If the generator function does not catch the passed-in exception, or
raises a different exception, then that exception propagates to the caller.
+ In typical use, this is called with a single exception instance similar to the
+ way the :keyword:`raise` keyword is used.
+
+ For backwards compatability, however, the second signature is
+ supported, following a convention from older versions of Python.
+ The *type* argument should be an exception class, and *value*
+ should be an exception instance. If the *value* is not provided, the
+ *type* constructor is called to get an instance. If *traceback*
+ is provided, it is set on the exception, otherwise any existing
+ :attr:`~BaseException.__traceback__` attribute stored in *value* may
+ be cleared.
+
.. index:: exception: GeneratorExit