Skip to content

Iteration exhaustion branch of asynchronous for loop is shown as missing #1158

Closed
@manueljacob

Description

@manueljacob
import asyncio

async def async_gen():
    yield 1

async def async_test():
    a = None
    async for i in async_gen():
        print(i)

asyncio.run(async_test())

I’ve run coverage run --branch script.py with Python 3.9.2 + coverage 5.5 and from Git commit 40c87e0.

I would expect that no line or branch is shown as missing, however branch 8->exit is shown as missing.

Similarly, when using the following script, branch 8->11 is shown as missing, although running the script fails at line 11.

import asyncio

async def async_gen():
    yield 1

async def async_test():
    a = None
    async for i in async_gen():
        print(i)
    else:
        zzz

asyncio.run(async_test())

When removing the a = None line or running on PyPy3.7 v7.3.4, no line or branch is shown as missing.

Also, with the following synchronous version, no line or branch is shown as missing:

def sync_gen():
    yield 1

def sync_test():
    a = None
    for i in sync_gen():
        print(i)

sync_test()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcpythonReported as a bug in CPythonnot our bugThe problem was elsewhere

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions