Skip to content

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

@Avasam

Description

@Avasam
  • 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions