[Python-ideas] Enhance definition of functions

Antoine Pitrou solipsis at pitrou.net
Fri Aug 2 15:55:02 CEST 2013

Le Fri, 2 Aug 2013 22:48:33 +1000,
Nick Coghlan <ncoghlan at gmail.com> a
écrit :
> I would also tweak the early binding syntax to require an additional
> keyword to make it read more like English:
>     seq = []
>     for i in range(10):
>         seq.append(?.f) given i=i in:
>             def f(): return i
>     assert [f() for f in seq] == list(range(10))

I think any "inline function" proposal should focus on callback-based
programming for its use cases. In this context, you usually have one or
two callbacks (two in Twisted-style programming: one for success, one
for failure), passed positionally to a consuming function:

    loop.create_connection((host, port), @cb, @eb) where:
        def cb(sock):
            # Do something with socket
        def eb(exc):
                "Failed connecting to %s:%s", host, port)



More information about the Python-ideas mailing list