[Python-ideas] 'where' statement in Python?

Masklinn masklinn at masklinn.net
Wed Jul 21 12:39:22 CEST 2010

On 2010-07-21, at 02:09 , Carl M. Johnson wrote:
> Questions:
> 1.) It looks like a lot of the complexity of PEP 3150 is based on
> wanting thing like this to work:
> x[index] = 42 given:
>    index = complicated_formula
> To make that work, you need to figure out if index is a nonlocal or a
> global or what in order to emit the right bytecode. What happens if we
> just give up that use case and say that anything on the assignment
> side of the initial = gets looked up in the original namespace? In
> other words, make 3150 more similar to the sugar:

I quite agree with that, the where/given block/scope should only apply to the expression directly to the left of it. So only the RHS should be concerned, and LHS is out of that scope.

And that expression would be written as:

operator.setitem(x, index, 42) given:
    index = complicated_formula

I think the first Torture Test block is misguided, and I'd be −0.5 on such a complex feature.

More information about the Python-ideas mailing list