Skip to content

B038 false positives #455

@xqt

Description

@xqt

having the following code;

 mylist = list(range(5))
 for item in mylist:
    if item == 2:
        mylist.remove(item)  # <- badly detects B038 here
        break

bugbear badly detects B038.

Sample: https://doc.wikimedia.org/pywikibot/master/_modules/proofreadpage.html#ProofreadPage
in index property (search for def index). As B038 is descibed as Found a mutation of a mutable loop iterable inside the loop body. Changes to the iterable of a loop such as calls to list.remove() or via del can cause unintended bugs. This rule should be an optionated warning instead of a general rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions