From: R David Murray Date: Sat, 18 Aug 2012 00:49:24 +0000 (-0400) Subject: Merge #15355: Mention already-executing Exception in generator docs. X-Git-Tag: v3.3.0rc1~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f66903631978d6b84031375a9da8ca12c7f6972f;p=python Merge #15355: Mention already-executing Exception in generator docs. Patch by Chris Jerdonek. --- f66903631978d6b84031375a9da8ca12c7f6972f diff --cc Doc/reference/expressions.rst index 9624b601b9,72ad95ea31..a5f376695a --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@@ -355,30 -352,17 +355,37 @@@ resumed before it is finalized (by reac garbage collected), the generator-iterator's :meth:`close` method will be called, allowing any pending :keyword:`finally` clauses to execute. +When ``yield from `` is used, it treats the supplied expression as +a subiterator. All values produced by that subiterator are passed directly +to the caller of the current generator's methods. Any values passed in with +:meth:`send` and any exceptions passed in with :meth:`throw` are passed to +the underlying iterator if it has the appropriate methods. If this is not the +case, then :meth:`send` will raise :exc:`AttributeError` or :exc:`TypeError`, +while :meth:`throw` will just raise the passed in exception immediately. + +When the underlying iterator is complete, the :attr:`~StopIteration.value` +attribute of the raised :exc:`StopIteration` instance becomes the value of +the yield expression. It can be either set explicitly when raising +:exc:`StopIteration`, or automatically when the sub-iterator is a generator +(by returning a value from the sub-generator). + + .. versionchanged:: 3.3 + Added ``yield from `` to delegate control flow to a subiterator + +The parentheses can be omitted when the :keyword:`yield` expression is the +sole expression on the right hand side of an assignment statement. + .. index:: object: generator - The following generator's methods can be used to control the execution of a - generator function: + + Generator-iterator methods + ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + This subsection describes the methods of a generator iterator. They can + be used to control the execution of a generator function. + + Note that calling any of the generator methods below when the generator + is already executing raises a :exc:`ValueError` exception. .. index:: exception: StopIteration