Re: [Python-ideas] Async Lambda syntax

Hello all, I was developing a script using an asyncio-based API, when I came across the need to define an asynchronous lambda. I found this syntax does not currently exist. Obviously I could have (and did) just write a regular coroutine, but for simple one-line functions and such, I think an asynchronous lambda syntax would be useful. I do not have the experience to write a PEP or implement this, so I was wondering what you all think of the idea. What I was thinking: foo = async lambda a, b: b + await bar(a I posted an issue <https://bugs.python.org/issue33447> on the issue tracker suggesting this, and was directed to this mailing list. Thanks, Noah

On 5/18/2018 4:53 PM, Noah Simon wrote:
Not really.
PEP8 intentionally and properly discourages 'name = lambda ...' as inferior to 'def name(...'. For the above, async def foo(a, b): return b + await bar(a)
I posted an issue <https://bugs.python.org/issue33447> on the issue tracker suggesting this, and was directed to this mailing list.
-- Terry Jan Reedy

On Fri, May 18, 2018 at 1:53 PM, Noah Simon <noahs2003@gmail.com> wrote:
This is the obvious syntax: it's unambiguous and consistent with the rest of the async/await syntax. Probably it's the only syntax worth considering. The question will be: does the need actually come up often enough in real life to be worth adding things to the language? Do you have any examples? Can you show what you were actually trying to do? Real examples are much more convincing than foo/bar examples. -n -- Nathaniel J. Smith -- https://vorpus.org

On 5/18/2018 4:53 PM, Noah Simon wrote:
Not really.
PEP8 intentionally and properly discourages 'name = lambda ...' as inferior to 'def name(...'. For the above, async def foo(a, b): return b + await bar(a)
I posted an issue <https://bugs.python.org/issue33447> on the issue tracker suggesting this, and was directed to this mailing list.
-- Terry Jan Reedy

On Fri, May 18, 2018 at 1:53 PM, Noah Simon <noahs2003@gmail.com> wrote:
This is the obvious syntax: it's unambiguous and consistent with the rest of the async/await syntax. Probably it's the only syntax worth considering. The question will be: does the need actually come up often enough in real life to be worth adding things to the language? Do you have any examples? Can you show what you were actually trying to do? Real examples are much more convincing than foo/bar examples. -n -- Nathaniel J. Smith -- https://vorpus.org
participants (3)
-
Nathaniel Smith
-
Noah Simon
-
Terry Reedy