[Python-ideas] PEP 572: Statement-Local Name Bindings

Brendan Barnwell brenbarn at brenbarn.net
Wed Feb 28 14:35:18 EST 2018


On 2018-02-28 07:18, Chris Angelico wrote:
> Except that assignment is evaluated RHS before LHS as part of a single
> statement. When Python goes to look up the name "a" to store it (as
> the final step of the assignment), the SLNB is still active (it's
> still the same statement - note that this is NOT expression-local), so
> it uses the temporary.

	Wait, so you're saying that if I do

a = (2 as a)

	The "a = " assignment assigns to the SLNB, and so is then discarded 
after the statement finishes?

	That seems very bad to me.  If there are SLNBs with this special "as" 
syntax, I think the ONLY way to assign to an SLNB should be with the 
"as" syntax.  You shouldn't be able to assign to an SLNB with regular 
assignment syntax, even if you created an SNLB with the same name as the 
LHS within the RHS.

-- 
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is no 
path, and leave a trail."
    --author unknown


More information about the Python-ideas mailing list