Skip to content

Commit

Permalink
PEP 572: Fix example to more accurately reflect reality
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Apr 11, 2018
1 parent 356c97e commit 582dfee
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pep-0572.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,14 @@ scope, which will succeed; but it will evaluate everything else in a function::
prefixed_names = <listcomp>(iter(names))

The name ``prefix`` is thus searched for at global scope, ignoring the class
name. Under the proposed semantics, this name will be eagerly bound, being
approximately equivalent to::
name. Under the proposed semantics, this name will be eagerly bound; and the
same early binding then handles the outermost iterable as well. The list
comprehension is thus approximately equivalent to::

class X:
names = ["Fred", "Barney", "Joe"]
prefix = "> "
def <listcomp>(prefix=prefix):
def <listcomp>(names=names, prefix=prefix):
result = []
for name in names:
result.append(prefix + name)
Expand All @@ -159,8 +160,7 @@ be late-bound as usual.

One consequence of this change is that certain bugs in genexps will not
be detected until the first call to ``next()``, where today they would be
caught upon creation of the generator. TODO: Discuss the merits and costs
of amelioration proposals.
caught upon creation of the generator. See 'open questions' below.


Recommended use-cases
Expand Down

0 comments on commit 582dfee

Please sign in to comment.