Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
manueljacob opened this issue May 4, 2021 · 5 comments
Closed
Labels
bug Something isn't working cpython Reported as a bug in CPython not our bug The problem was elsewhere

Comments

@manueljacob
Copy link
Contributor

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()
@manueljacob manueljacob added the bug Something isn't working label May 4, 2021
@jorants
Copy link

jorants commented Jun 23, 2021

Came across the same problem when using coverage on beanie which uses a lot of async for loops. Might be related to #1176

nedbat added a commit that referenced this issue Jun 23, 2021
@nedbat
Copy link
Owner

nedbat commented Jun 23, 2021

I added a test for this on a branch, and it seems to do the right things for these Python versions: 3.7.10, 3.8.10, and 3.10.0b3.
It doesn't trace correctly on Python 3.9.5.
So this seems like a problem in Python 3.9. Can you confirm?

@jorants
Copy link

jorants commented Jul 5, 2021

I tried the same tests from beanie on 3.8 and there it does seem to work correctly, i can not easily test the others right now.

@nedbat
Copy link
Owner

nedbat commented Jul 13, 2021

I've reported this against CPython https://bugs.python.org/issue44621.

@nedbat nedbat added the cpython Reported as a bug in CPython label Jul 13, 2021
nedbat added a commit that referenced this issue Jul 13, 2021
@nedbat
Copy link
Owner

nedbat commented Oct 7, 2021

This CPython bug has been fixed in 3.9.7.

@nedbat nedbat closed this as completed Oct 7, 2021
@nedbat nedbat added the not our bug The problem was elsewhere label Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cpython Reported as a bug in CPython not our bug The problem was elsewhere
Projects
None yet
Development

No branches or pull requests

3 participants