|
|
Log in / Subscribe / Register

A Welcome Syntax

A Welcome Syntax

Posted Apr 24, 2025 11:13 UTC (Thu) by mb (subscriber, #50428)
In reply to: A Welcome Syntax by farnz
Parent article: Template strings accepted for Python 3.14

I really don't understand what the problem is that you are talking about.
If you want parenthesis after await, then just add them. You can do that today.

$ cat t.py
import asyncio

async def x():
    print('A')
    await asyncio.sleep(1)
    print('B')
    await(asyncio.sleep(1))
    print('C')

asyncio.run(x())

$ python3 t.py
A
B
C


to post comments

A Welcome Syntax

Posted Apr 24, 2025 11:28 UTC (Thu) by farnz (subscriber, #17727) [Link]

Ideally, I would get a syntax error if I wrote await asyncio.sleep(5), because the mental model my Python-using colleagues have is that keyword expression means "return the value of expression to the caller of this function somehow", whereas keyword(expression) means "have keyword call expression and give me back a value".

And because they don't want to return from this function (they want to wait for expression to evaluate, which involves hardware accesses), they try to put the minimum number of awaits in that seems to work for them, scoping them as broadly as possible and dragging other people in when they can't guess their way to working code.

A Welcome Syntax

Posted Apr 24, 2025 18:28 UTC (Thu) by Wol (subscriber, #4433) [Link] (2 responses)

> I really don't understand what the problem is that you are talking about.
> If you want parenthesis after await, then just add them. You can do that today.

The problem is you ass-u-me-ing that the people doing the program know to do it.

And training is not the answer when (as seems to be the case here) they are doing it maybe twice in a blue moon.

I think you need a spell doing 1st-line support for people who either (a) don't program as part of their work, or (b) for whom it is a necessary evil. Most of them are unteachable ...

Cheers,
Wol

A Welcome Syntax

Posted Apr 24, 2025 18:37 UTC (Thu) by mb (subscriber, #50428) [Link] (1 responses)

>The problem is you ass-u-me-ing that the people doing the program know to do it.

No.
The complaint was that the people want to use parenthesis, because that better fits to how they think.
Well, I'm fine with that.
And that Python should allow that.

But that's actually possible with current Python.
Therefore, I really don't know where the problem is.

If you want to use parenthesis, use them.
If you don't want to use parenthesis, don't use them.

And if you don't know the language, learn it.
This is orthogonal to whether async is spelled with or without parenthesis.

A Welcome Syntax

Posted Apr 25, 2025 8:53 UTC (Fri) by farnz (subscriber, #17727) [Link]

No.
The complaint is that Python permits you to use a space instead, which results in people getting confused by the code they copy-and-paste from elsewhere, since they don't understand why they're "returning" something here, and come up with all sorts of weird mental models for how await changes the context after it - e.g. that await foo() + bar() is semantically the same as await foo() + await bar().

Python should not use the same syntactic convention for "things that return a value from this function to its caller (such as yield and return)" and "things that evaluate something into a different type of value (such as await)".

Adopting a Rust-like "postfix await" would also work for this - because it means that it's a different syntax for a different behaviour - but I would expect that to be a much bigger sell to Python people than parens.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds