File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -974,11 +974,11 @@ which yields the same values as the corresponding list comprehension::
974974Thus, the example above is roughly equivalent to defining and calling
975975the following generator function::
976976
977- def make_generator_of_squares(iterable ):
978- for x in iterable :
977+ def make_generator_of_squares(iterator ):
978+ for x in iterator :
979979 yield x ** 2
980980
981- make_generator_of_squares(range(10))
981+ make_generator_of_squares(iter( range(10) ))
982982
983983The enclosing parentheses can be omitted in calls when the generator
984984expression is the only positional argument and there are no keyword
@@ -1004,6 +1004,15 @@ rather than at the point where the first value is retrieved::
10041004 ...
10051005 NameError: name 'nonexistent_iterable' is not defined
10061006
1007+ After the expression is evaluated, an iterator is created
1008+ from the result, as if :py:func: `iter ` was called on it.
1009+ Any error raised when creating the iterator is also emitted immediately::
1010+
1011+ >>> (x ** 2 for x in None)
1012+ Traceback (most recent call last):
1013+ ...
1014+ TypeError: 'NoneType' object is not iterable
1015+
10071016All other expressions are evaluated lazily, in the same fashion as normal
10081017generators (that is, when the iterator is asked to yield a value)::
10091018
You can’t perform that action at this time.
0 commit comments