Skip to content
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

B909 False-positive: Detects immediate break but not return #12640

Closed
Avasam opened this issue Aug 2, 2024 · 0 comments · Fixed by #12646
Closed

B909 False-positive: Detects immediate break but not return #12640

Avasam opened this issue Aug 2, 2024 · 0 comments · Fixed by #12646
Assignees
Labels
bug Something isn't working

Comments

@Avasam
Copy link
Contributor

Avasam commented Aug 2, 2024

  • List of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.
    B909

  • A minimal code snippet that reproduces the bug.

def __pop_image_type(split_image: Iterable[AutoSplitImage], image_type: ImageType):
    for image in split_image:
        if image.image_type == image_type:
            split_image.remove(image)
            return image

    return None
  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.
    ruff check . --isolated --select=B909 --preview
  • The current Ruff version (ruff --version).
    ruff 0.5.6

See the reproducer above, I'd expect that to pass, given that the below code also passes, but is much less cleaner:

def __pop_image_type(split_image: list[AutoSplitImage], image_type: ImageType):
    for image in split_image:
        if image.image_type == image_type:
            split_image.remove(image)
            break
    else:
        return None

    return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants