[Python-ideas] Where-statement (Proposal for function expressions)
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Jul 17 04:02:34 CEST 2009
Daniel Stutzbach wrote:
> If the
> left-hand side were in the where-block's scope, then:
>
> x = 0
> x = i where:
> i = 5
> print x
>
> Would print "0" not "5".
My intuitive expectations are different for assignment
to a bare name vs. assignment to an item or attribute.
In
x = i where:
i = 5
I would expect x to be bound in the current scope,
not the where-block scope. But I would expect
x[i] = 5 where:
x = y
i = 7
to be equivalent to
y[7] = 5
i.e. both x and i are *evaluated* in the where-block
scope.
I'm not sure where this leaves us with respect to
augmented assignment, though. If you follow it to
its logical conclusion, then
x += i where:
i = 5
should be equivalent to
x = x.__iadd__(i) where:
i = 5
and then the evaluation and rebinding of 'x' would
happen in different scopes!
--
Greg
More information about the Python-ideas
mailing list