New text about "from __future__ import generators".

This commit is contained in:
Tim Peters 2001-07-17 04:28:28 +00:00
parent 1c2f3d4697
commit 67c021817d
1 changed files with 9 additions and 4 deletions

View File

@ -125,10 +125,15 @@ Specification: Yield
yield_stmt: "yield" expression_list yield_stmt: "yield" expression_list
"yield" is a new keyword, so a future statement[8] is needed to phase "yield" is a new keyword, so a future statement[8] is needed to phase
this in. [XXX spell this out -- but new keywords have ripple effects this in: in the initial release, a module desiring to use generators
across tools too, and it's not clear this can be forced into the future must include the line
framework at all -- it's not even clear that Python's parser alone can
be taught to swing both ways based on a future stmt] from __future__ import generators
near the top (see PEP 236[8]) for details). Modules using the
identifier "yield" without a future statement will trigger warnings.
In the following release, yield will be a language keyword and the
future statement will no longer be needed.
The yield statement may only be used inside functions. A function that The yield statement may only be used inside functions. A function that
contains a yield statement is called a generator function. A generator contains a yield statement is called a generator function. A generator