[Python-ideas] YAML (yet-another-multiline-lambda)

Serhiy Storchaka storchaka at gmail.com
Tue Oct 22 20:23:40 CEST 2013


22.10.13 13:10, Antony Lee написав(ла):
> As the issue has been (indirectly) raised again in the recent context
> manager thread, I would like to propose yet another syntax for multiline
> lambdas...

Most of use cases for multiline lambdas actually don't needed multiline 
lambdas.

> target = (def f(arg):
>      <...>)

def target(arg):
     ...

> callbacks = {
>      "foo":
>          (def foo():
>              <...>), # note how the parentheses disambiguate where the
> last comma belongs
>      "bar":
>          (def bar():
>              <...>)
> }

def class_to_map(cls):
     return {n: f for n, f in cls.__dict__items() if n[0] != '_'}

@class_to_map
class callbacks:
     @staticmethod
     def foo():
         ...
     @staticmethod
     def bar():
         ...




More information about the Python-ideas mailing list