[Python-ideas] Where-statement (Proposal for function expressions)

MRAB python at mrabarnett.plus.com
Fri Jul 17 02:28:35 CEST 2009


Jan Kaliszewski wrote:
> 17-07-2009, 00:51 Mike Meyer <mwm-keyword-python.b4bdba at mired.org> wrote:
> 
>> That they cause problems with your first attempt at
>> describing an implementation certainly isn't reason to disallow them
>> all by itself.
> 
> But, it isn't a problem of implementation. I don't see any reasonable
> *semantics* of return or yield within where-block in proposed form.
> return/yield statements seem to be completely unnecessary in this context.
> (Of course, I don't say about return/yield statements within functions
> defined within where-block).
> 
I think that a return, yield, break or continue in a where-block would
in a sense be no different to one in a normal suite, except, of course,
that there happens to be a local namespace.

foo = bar where:
     if condition:
         return
     bar = "bar"

would be equivalent to:

local:
     nonlocal foo
     if condition:
         return
     bar = "bar"
     foo = bar

(I accept that 'nonlocal' might not be the right keyword, but you get
the idea.)



More information about the Python-ideas mailing list