[Python-3000] Requiring () around lambda's argument list

Guido van Rossum guido at python.org
Mon May 1 22:39:26 CEST 2006


I'm running into something that may make me require parentheses around
lambda's argument list. Basically, I'm settled on the following syntax
for adding optional annotations (formerly known as type declarations
:-) to parameters definitions:

  def foo(arg1name: typeexpr = defaultexpr, arg2: typeexpr =
defaultexpr, ...): ...

But the same syntax production that's used for formal parameters
inside parentheses is also used *without* parentheses in the syntax
for lambda. Unfortunately the above extension makes it ambiguous; when
the parser sees

  lambda arg1name : ...

it can't tell whether the colon is the colon that ends the formal
parameter list or whether it's a colon that introduces an optional
parameter annotation.

I really don't want to restart the syntax debate for parameter
annotations, so I feel forced to require parentheses around lambda's
parameter list.

Fortunately this is at least one of those things that we can fix with
a purely syntactical source code transformation...

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list