Typed Anonymous Functions (lamdef)

And as a short bonus, I also disagree with your FAQ section “Why not extend lambda to support type hints?

If you desire to have something like this:
f = lambda (x: int, y: int): x + y
PEP 3113 removes Tuple Parameter Unpacking is one of the strongest reason:

No, quite the opposite: Since PEP 3113 removed Tuple Parameter Unpacking, one could now reuse that Python 2 syntax to allow lambda expression parameters to be parenthesized.

And if you desire to have something like this (no space between lambda and ():
a = lambda(x: int, y: int): x + y
This would allow lambda to have two ways (lambda(x): vs lambda x:) to do the same thing, which violates the Zen of Python: There should be one-- and preferably only one --obvious way to do it.

  1. Space or no space. There is no difference.
  2. The Zen of Python does not say that there must not be more than one way to do it. And, anyway, lamdef would be a second way as well…
5 Likes