[Python-ideas] Multi Statement Lambdas
rosuav at gmail.com
Sun Oct 21 20:44:47 EDT 2018
On Mon, Oct 22, 2018 at 11:40 AM Steven D'Aprano <steve at pearwood.info> wrote:
> 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".
This is true. But nobody ever says "oh but it's impossible to
unit-test that for-loop". It's just a block of code within a function,
and doesn't NEED to be separately tested. A lambda function should
also behave as a subsection of its surrounding code, and thus not need
to be unit-tested. I don't know why this is a problem for lambda
functions and not for comprehensions or statements. *shrug*
> > 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.
Also very true... but I'm trying to be welcoming rather than just
rudely say "it hasn't been solved for 25 years so there's no way you
could possibly have solved this". After all, we've had plenty of other
proposals that took many years to finally happen.
Slim is nonzero and I'm open to the possibility that there is now a
new syntax that would work.
More information about the Python-ideas