-
Notifications
You must be signed in to change notification settings - Fork 109
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
B038 false positive in 24.1.15 + 24.1.16 #451
Comments
cc @mimre25 for feedback on this as it may also impact the ruff implementation |
Looks similar to mydicts = {'a': {'foo': 1, 'bar': 2}}
for mydict in mydicts:
if mydicts.get('a', ''):
print(mydict['foo']) B038 is complaining about any instance of an object method called inside the loop that object is the iterator for, without checking whether the loop is modifying it. |
Agree this looks a bad / annoying false positive. Will take a fix for this asap and release. Thanks for reporting. |
Oh snap, I actually ran this on a quite big code-base as a test and I didn't have any false positives reported. I'll take a look and see if I can fix this. Thanks for reporting this and tagging me 🙂 |
Previous implementation produced false positives. This fixes those and adds some more tests. See PyCQA#451
I've also encountered this false positive for copy() function d = {}
for _ in d:
copied = d.copy() |
* fix(b038): Restrict rule to mutating functions only Previous implementation produced false positives. This fixes those and adds some more tests. See #451 * fix(b038): Add dict.popitem() to list of mutating functions
* fix(b038): Restrict rule to mutating functions only Previous implementation produced false positives. This fixes those and adds some more tests. See PyCQA/flake8-bugbear#451 * fix(b038): Add dict.popitem() to list of mutating functions
First of all thanks for this new B038 new rule, it's a great addition!
Using flake8-bugbear
24.1.15
The following code is flagged.
Although a method of
some_list
is called I believe this doesn't have any effect on the mutableThe text was updated successfully, but these errors were encountered: