Repository navigation
py/compile: Do not await __aiter__ special method return value. - #6272
jonathanhogg wants to merge 2 commits into
Conversation
__aiter__ should return an async-iterable object, but is not itself awaitable - as per CPython documentation. See micropython#6267.
Remove async keyword from __aiter__ methods to match CPython/PEP452-final spec. Also remove await of f() from __aiter__ method in async_for2.py as this is no longer valid (updated expected output to match).
|
The transition to uasyncio V3 introduces other breaking changes in the interests of CPython compatibility, so in my view now is the time to do this. |
|
CPython's syntax rules have changed. V3.6.9 accepts either async def __aiter__(self):
print('aiter')
return selfor def __aiter__(self):
print('aiter')
return selfCPython 3.8.0 accepts only the latter, throwing a cryptic exception in the former case. |
I think this is consistent with this message on the original CPython bug, which suggested that the change be staggered in with a I've just tested on a 3.7 build and using async fails: |
I was thinking to wait until after v1.13 is released to change/fix this, but, I think you're right, let's do it now. |
|
Rebased, squashed (in this case it's good to have the code change go with the change to the tests) and merged in 37e1b5c Thank you! |
…t-fix Force pin 21 high; patch; need to diagnose further
As per discussion in #6267, the final PEP492 spec says that the
__aiter__()method should not return an awaitable. This PR changes the compiler to not compile in an await and updates the async for tests to match.Note that the test in
async_for2.pyhas had to be more modified in behaviour as well as syntax as it can no longer yield in the__aiter__()method. I've just removed the call toawait f()and the matching output completely.Have run the UNIX port tests successfully on macOS and also tested with my own async iterable code on the ESP32 port.
Note: This will be a breaking change to any (not precompiled) code that currently defines
__aiter__methods usingawait.