[Python-ideas] Where-statement (Proposal for function expressions)
Arnaud Delobelle
arnodel at googlemail.com
Fri Jul 17 18:35:52 CEST 2009
On 17 Jul 2009, at 03:02, Greg Ewing wrote:
>
> [...] 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.
>
So would I, given that the statement
x[i] = 5
is the really the same as the expression
x.__setitem__(i, 5)
> 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!
Indeed. But why not simply evaluate the whole statement in the where
scope, with all names not bound in the where scope declared as nonlocal?
i.e
x[i], y = foo(a), b where:
i = 7
def foo(x):
return bar(x, x)
would be equivalent to:
def _():
nonlocal x, y, b
i = 7
def foo(x):
return bar(x, x)
x[i], y = foo(a), b
_()
--
Arnaud
More information about the Python-ideas
mailing list