Skip to content

Commit 33bb301

Browse files
committed
Address review
1 parent e475a42 commit 33bb301

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

Doc/reference/expressions.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,11 @@ which yields the same values as the corresponding list comprehension::
974974
Thus, the example above is roughly equivalent to defining and calling
975975
the 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

983983
The enclosing parentheses can be omitted in calls when the generator
984984
expression 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+
10071016
All other expressions are evaluated lazily, in the same fashion as normal
10081017
generators (that is, when the iterator is asked to yield a value)::
10091018

0 commit comments

Comments
 (0)