[Python-ideas] Multi Statement Lambdas

Steven D'Aprano steve at pearwood.info
Sun Oct 21 20:34:27 EDT 2018


On Mon, Oct 22, 2018 at 10:25:19AM +1100, Chris Angelico wrote:
> On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy <tjreedy at udel.edu> wrote:

> > Except for relatively trivial expressions, this is a bad thing.  All
> > functions created from lambda expressions get the same pseudo-name
> > '<lambda>'.  This can make tracebacks worse.  Perhaps more importantly,
> > proper testing may become harder.
> 
> The same considerations bite comprehensions, too, but we don't
> discourage their use. So I don't think this should be a killer - not
> on its own, anyhow.

But we *do* discourage large, complex comprehensions, especially nested 
ones. And more importantly, comprehensions are also limited to a single 
expression, like lambda, and if you need a multi-statement comprehension 
we say "turn it into a for-loop".


> I do not currently support any proposed syntax for multi-statement
> lambda functions, mainly because they've all been ugly. But maybe
> there'll be one, somewhere, some day, that makes sense.

After 25 years, I think the odds of that are pretty slim.


-- 
Steve


More information about the Python-ideas mailing list