[issue33447] Asynchronous lambda syntax

2018-05-31 Thread Thomas Dybdahl Ahle


Thomas Dybdahl Ahle  added the comment:

Just wanted to add another use-case. In a project I'm working on, we are 
building a lot of graphs using code like this:

```
nodes = [
Node('node-name1',
 children=[...],
 classifier=has_foo),
Node('node-name2',
 children=[...],
 classifier=has_bar),
...
]
```
where `has_foo` and `has_bar` are async functions.
Sometimes it would be useful to combine two functions with
```
Node('node-name',
 children=[...],
 classifier=async lambda: x: await has_bar(x) or await has_foo(x))
```
If this function was to be an `async def`, rather than `async lambda`, it would 
have to be defined far away from where it is used. This doesn't always make 
sense semantically.

I don't think this example on its own is enough to warrant new syntax in the 
language, but if somebody is collecting "multiple use cases to justify not just 
using async def first", perhaps it's worth including.

--
nosy: +thomasahle

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33447] Asynchronous lambda syntax

2018-05-18 Thread Terry J. Reedy

Terry J. Reedy  added the comment:

The only thing special about functions defined with lambda expressions rather 
than def statements is the generic name attribute '' instead of a 
specific name.  PEP8 intentionally and properly discourages 'name = lambda ...' 
as inferior to 'def name(...'.

For your example, 

async def foo(a, b): return 5 + await bar(b)

For inline function expressions, as in function calls, the obvious proposals 
would be to reuse 'async' in f(async lambda a, b: ...) or a new keyword, such 
as 'alambda' or 'asynclambda' or ... . Either would need multiple use cases to 
justify not just using async def first.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33447] Asynchronous lambda syntax

2018-05-18 Thread Yury Selivanov

Yury Selivanov  added the comment:

The syntax for async lambdas doesn't look nice and I, personally, don't see 
that many use cases for them to justify adding new syntax.  And this would need 
a new PEP. 

I suggest to start a discussion on the Python-ideas mailing list if this is 
something you want to see in Python.

--
components: +Interpreter Core -asyncio
resolution:  -> postponed
stage:  -> resolved
status: open -> closed
versions: +Python 3.8 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33447] Asynchronous lambda syntax

2018-05-08 Thread Noah Simon

Noah Simon  added the comment:

Actually, you wouldn't even need to import asyncio.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33447] Asynchronous lambda syntax

2018-05-08 Thread Noah Simon

New submission from Noah Simon :

It would be very useful to add an asynchronous lambda syntax, as a shortcut for 
coroutines. I'm not experienced enough to write a PEP or edit the C source, but 
I have some ideas for syntax:

import asyncio
foo = async lambda a,b: 5 + await bar(b)

--
components: asyncio
messages: 316304
nosy: Noah Simon, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Asynchronous lambda syntax
type: enhancement
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com