The current behaviour of await in a Python script differs between µPy and CPy.
Here's MicroPython 1.12:
>>> def a(x):
... print(1)
... await b(2)
... print(3)
...
>>> a
<generator>
>>>
And here is CPython 3.8:
>>> def a(x):
... print(1)
... await b(2)
... print(3)
...
File "<stdin>", line 3
SyntaxError: 'await' outside async function
>>>
There are three ways to resolve this (at some point):
- document the difference
- make µPy reject with the same error as CPy
- do something new
That third option, would be to change the µPy behavior so that def a(): is not turned into a coroutine, but kept as regular function. This is 100% compatible with CPy, since to make the above work identically on both, you have to add the async keyword anyway.
Allowing await to be used in regular functions offers the opportunity to extend µPy in such a way that it solves the red/blue problem. I have some ideas on how to get there, and may actually have a go at implementing it, but it all hinges on which of the three decision µPy takes (at some point).
Either way, the above difference is real and will eventually need to be addressed, hence this issue.
Minor edit: await still needs an awaitable as arg. Nothing changed in that respect.
The current behaviour of
awaitin a Python script differs between µPy and CPy.Here's MicroPython 1.12:
And here is CPython 3.8:
There are three ways to resolve this (at some point):
That third option, would be to change the µPy behavior so that
def a():is not turned into a coroutine, but kept as regular function. This is 100% compatible with CPy, since to make the above work identically on both, you have to add theasynckeyword anyway.Allowing
awaitto be used in regular functions offers the opportunity to extend µPy in such a way that it solves the red/blue problem. I have some ideas on how to get there, and may actually have a go at implementing it, but it all hinges on which of the three decision µPy takes (at some point).Either way, the above difference is real and will eventually need to be addressed, hence this issue.
Minor edit:
awaitstill needs an awaitable as arg. Nothing changed in that respect.