summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-12-23 23:31:57 (GMT)
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-12-23 23:31:57 (GMT)
commit2654b86e88aa14f0916cfa10ecdbc0852e7e6795 (patch)
tree4dfe31ce3f21cea1854bea3db4c95f5ddd06d70d /Doc/reference
parent70dcef478936c6df43bc6f812b52d58a0cd219b4 (diff)
downloadcpython-2654b86e88aa14f0916cfa10ecdbc0852e7e6795.zip
cpython-2654b86e88aa14f0916cfa10ecdbc0852e7e6795.tar.gz
cpython-2654b86e88aa14f0916cfa10ecdbc0852e7e6795.tar.bz2
Link to "yield from" examples in yield documentation.
This commit also simplifies the more advanced "yield from" example and removes unused function parameters.
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/expressions.rst12
1 files changed, 11 insertions, 1 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 41523cb..429fee4 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -320,7 +320,8 @@ Yield expressions
yield_atom: "(" `yield_expression` ")"
yield_expression: "yield" [`expression_list` | "from" `expression`]
-The :keyword:`yield` expression is only used when defining a generator function,
+The :keyword:`yield` expression is only used when defining a :term:`generator`
+function,
and can only be used in the body of a function definition. Using a
:keyword:`yield` expression in a function definition is sufficient to cause that
definition to create a generator function instead of a normal function.
@@ -438,6 +439,12 @@ is already executing raises a :exc:`ValueError` exception.
other exception, it is propagated to the caller. :meth:`close` does nothing
if the generator has already exited due to an exception or normal exit.
+
+.. index:: single: yield; examples
+
+Examples
+^^^^^^^^
+
Here is a simple example that demonstrates the behavior of generators and
generator functions::
@@ -465,6 +472,9 @@ generator functions::
>>> generator.close()
Don't forget to clean up when 'close()' is called.
+For examples using ``yield from``, see :ref:`pep-380` in "What's New in
+Python."
+
.. seealso::