QUERY · ISSUE
Add yield support in async function
enhancement
Checks
-
I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.
-
I've searched for existing issues regarding this feature, and didn't find any.
Description
Just in PEP 525, it's really easy to make a async generator instead of coding a new class with aiter and anext .
Just like this:
async def test():
for i in range(5):
await something
' yield i
Code Size
I believe this is an important syntax that makes asynchronous generation as convenient as normal generators.
Implementation
- I intend to implement this feature and would submit a Pull Request if desirable.
- I hope the MicroPython maintainers or community will implement this feature.
- I would like to Sponsor development of this feature.
CANDIDATE · PULL REQUEST
py: add async/await/async for/async with syntax
They are sugar for marking function as generator, "yield from"
and pep492 python "semantically equivalents" respectively.
Code size
unix before:
LINK micropython
text data bss dec hex filename
353064 1544 2176 356784 571b0 micropython
micropython file size = 359472 bytes
unix after:
LINK micropython
text data bss dec hex filename
356192 1544 2176 359912 57de8 micropython
micropython file size = 363568 bytes
stmhal before:
LINK build-PYBV10/firmware.elf
text data bss dec hex filename
284132 336 28500 312968 4c688 build-PYBV10/firmware.elf
firmware.elf file size = 565025 bytes
stmhal after:
LINK build-PYBV10/firmware.elf
text data bss dec hex filename
285732 336 28500 314568 4ccc8 build-PYBV10/firmware.elf
firmware.elf file size = 565561 byte