Skip to content

SyntaxError in await-for-in structure #4907

Description

@xiaxinmeng

RustPython fails to handle await-for-in structure even the await operation is in an asynchronous function. See the following example:

async def bar():
    [await print(i) for i in [1, 2, 3]]

Expected (on CPython 3.11): work normally

Got on RustPython:

SyntaxError: 'await' outside async function at line 141 column 5
    [await print(i) for i in [1, 2, 3]]
    ^

Environment
Ubuntu 18.04
RustPython 0.2.0
CPython 3.11.3

Activity

  1. jackoconnordev commented on Aug 5, 2025

    @jackoconnordev
    Contributor

    I might be wrong here but I think this can be closed. I've tried to reproduce the syntax error without success.

    Environment

    Chip: Apple M1
    OS: MacOS Sequoia 15.6
    RustPython: 0.4.0
    Python: 3.13.5

    Test script

    A simple script which uses asyncio runtime to call an async function which awaits the result of asyncio.sleep(1) twice inside a list comprehension. If the list comprehension succeeds, prints.

    import asyncio
    import time
    
    
    async def lc():
        [await asyncio.sleep(1) for _ in range(2)]
        print("lc done")
    
    
    start = time.time()
    
    loop = asyncio.new_event_loop()
    tasks = [
        loop.create_task(lc()),
    ]
    loop.run_until_complete(asyncio.wait(tasks))
    loop.close()
    
    end = time.time()

    RustPython output

    lc done

    CPython output

    lc done
  2. youknowone commented on Oct 6, 2026

    @youknowone
    Member

    The originally reported problem no longer reproduces on current main. Closing per the recheck in #8982.

    — commented by Grok 4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions