Skip to content

Missing empty continue branch during iteration #1179

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
ofek opened this issue Jun 19, 2021 · 2 comments
Closed

Missing empty continue branch during iteration #1179

ofek opened this issue Jun 19, 2021 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@ofek
Copy link

ofek commented Jun 19, 2021

Reproduce

System

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32

File

cov-bug.py

from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Generator, List


def recurse_artifacts(artifacts: List[str], root: Path) -> Generator[Path, None, None]:
    for artifact in artifacts:
        artifact = Path(artifact)
        if not artifact.is_absolute():
            artifact = root / artifact

        if artifact.is_file():
            yield artifact
        elif artifact.is_dir():
            yield from artifact.iterdir()


def main():
    with TemporaryDirectory() as d:
        project_dir = Path(d).resolve()
        build_dir = project_dir / 'dist'
        build_dir.mkdir()

        absolute_path = project_dir / 'absolute.whl'
        absolute_path.touch()
        (build_dir / 'test.tar.gz').touch()
        (build_dir / 'test.txt').touch()
        (build_dir / 'test.whl').touch()

        # Turning generator into list also fails:
        # for artifact in list(recurse_artifacts(['dist', str(absolute_path)], project_dir)):
        for artifact in recurse_artifacts(['dist', str(absolute_path)], project_dir):
            if artifact.name.endswith('.whl'):
                print('found wheel')
            elif artifact.name.endswith('.tar.gz'):
                print('found sdist')
            else:
                # print('skipping')
                continue

            print('uploading')


if __name__ == '__main__':
    main()

Command

$ coverage run cov-bug.py && coverage report --show-missing
found sdist
uploading
found wheel
uploading
found wheel
uploading
Name         Stmts   Miss  Cover   Missing
------------------------------------------
cov-bug.py      31      1    97%   39
------------------------------------------
TOTAL           31      1    97%

Additional context

The branch is discovered if you uncomment print('skipping')

@ofek ofek added the bug Something isn't working label Jun 19, 2021
@nedbat
Copy link
Owner

nedbat commented Jun 19, 2021

This was a long-standing issue with CPython, and a duplicate of #198. It's now fixed in CPython 3.10.

@nedbat nedbat closed this as completed Jun 19, 2021
@nedbat nedbat added the duplicate This issue or pull request already exists label Jun 19, 2021
@ofek
Copy link
Author

ofek commented Jun 19, 2021

My bad, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants