PEP 572: Alter the definition of assignment through SLNBs
This commit is contained in:
parent
c084673770
commit
f91ce9cb07
10
pep-0572.rst
10
pep-0572.rst
|
@ -38,13 +38,17 @@ and ``NAME`` is a simple name.
|
|||
|
||||
The value of such a named expression is the same as the incorporated
|
||||
expression, with the additional side-effect that NAME is bound to that
|
||||
value for the remainder of the current statement.
|
||||
value in all retrievals for the remainder of the current statement.
|
||||
|
||||
Just as function-local names shadow global names for the scope of the
|
||||
function, statement-local names shadow other names for that statement.
|
||||
They can also shadow each other, though actually doing this should be
|
||||
strongly discouraged in style guides.
|
||||
|
||||
Assignment to statement-local names is ONLY through this syntax. Regular
|
||||
assignment to the same name will remove the statement-local name and
|
||||
affect the name in the surrounding scope (function, class, or module).
|
||||
|
||||
Execution order and its consequences
|
||||
------------------------------------
|
||||
|
||||
|
@ -57,7 +61,7 @@ expectations. Some examples::
|
|||
a = (1 as y)
|
||||
print(y) # NameError
|
||||
|
||||
# For the evil people who write a=a++ in C
|
||||
# The assignment ignores the SLNB - this adds one to 'a'
|
||||
a = (a + 1 as a)
|
||||
|
||||
# Compound statements usually enclose everything...
|
||||
|
@ -259,6 +263,8 @@ Discrepancies in the current implementation
|
|||
shadow any other names from the same function); as an alternative, they
|
||||
could simply never appear, even when in scope.
|
||||
|
||||
3. Assigning 'through' a SLNB is not implemented yet.
|
||||
|
||||
|
||||
References
|
||||
==========
|
||||
|
|
Loading…
Reference in New Issue