PEP 572: Update implementation notes and add an example
This commit is contained in:
parent
c36c28ff72
commit
2f1b0d36fc
22
pep-0572.rst
22
pep-0572.rst
|
@ -117,7 +117,7 @@ These list comprehensions are all approximately equivalent::
|
|||
def g():
|
||||
for x in range(5):
|
||||
y = f(x)
|
||||
yield [y, y]
|
||||
yield [y, x/y]
|
||||
stuff = list(g)
|
||||
|
||||
# Using a statement-local name
|
||||
|
@ -135,6 +135,18 @@ avoided when ``def`` is an option. As the name's scope extends to the full
|
|||
current statement, even a block statement, this can be used to good effect
|
||||
in the header of an ``if`` or ``while`` statement::
|
||||
|
||||
# Current Python, not caring about function return value
|
||||
while input("> ") != "quit":
|
||||
print("You entered a command.")
|
||||
|
||||
# Current Python, capturing return value - four-line loop header
|
||||
while True:
|
||||
command = input("> ");
|
||||
if command == "quit":
|
||||
break
|
||||
print("You entered:", command)
|
||||
|
||||
# Proposed alternative to the above
|
||||
while (input("> ") as command) != "quit":
|
||||
print("You entered:", command)
|
||||
|
||||
|
@ -263,11 +275,9 @@ Discrepancies in the current implementation
|
|||
===========================================
|
||||
|
||||
1. SLNBs are implemented using a special (and mostly-invisible) name
|
||||
mangling. This works perfectly inside functions (including list
|
||||
comprehensions), but not at top level. Making this work at top-level
|
||||
and in class definitions would be very much of value.
|
||||
|
||||
2. Assigning 'through' a SLNB is not implemented yet.
|
||||
mangling. They may sometimes appear in globals() and/or locals() with
|
||||
their simple or mangled names (but buggily and unreliably). They should
|
||||
be suppressed as though they were guinea pigs.
|
||||
|
||||
|
||||
References
|
||||
|
|
Loading…
Reference in New Issue