Helper to emulate `async lambda`?
maxfischer2781 opened this issue · 3 comments
The ability to have an "async lambda
" has occasionally been requested but so far not implemented in Python. This might be a chicken-and-egg problem, but it would certainly have been useful internally. While the new Py3.10 PEG Parser would make the syntax easy enough, the Python backend seems arcane to me and would not be backwards compatible.
Consider whether asyncstdlib
could provide a backwards compatible helper to emulate async lambda
.
Current alternatives/workarounds:
asyncstdlib.apply
provides a means to combine alambda
with severalawait
ables.- a
lambda
and async generator can be combined to created an effective but obscure "async
lambda
":lambda x: (await x + 5 for _ in '_').__anext__()
This list will be updated as more arise.
Possible approaches:
Closing this for the time being. I'm not in favour of helpers for individual cases, since they don't actually cover the full lambda
usecase. Metaprogramming via macros, bytecode or whatever seems way too heavy to maintain, and wouldn't play well with other tools.