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

B023 False positives #1686

Closed
TomFryers opened this issue Jan 6, 2023 · 1 comment · Fixed by #1776
Closed

B023 False positives #1686

TomFryers opened this issue Jan 6, 2023 · 1 comment · Fixed by #1776
Assignees
Labels
bug Something isn't working

Comments

@TomFryers
Copy link
Contributor

False positive B023 errors are quite common with filter, reduce, key=, return and map. For instance, this code

unsorted_things = [(["foo", "bar"], 0), (["foobar", "barfoo"], 4), (["baz", "foo", "moo"], 1)]
for unsorted_thing, letter in unsorted_things:
    unsorted_thing.sort(key=lambda x: (x[letter], len(x)))

is fine, but it currently gets flagged as B023.

This was raised in Flake8 Bugbear in issue 303 (and 305) and fixed in 22.10.27.

Ignoring these does cause some false negatives, for instance if the filter or map is not evaluated before the next iteration, but this was deemed acceptable in the Bugbear issue.

@charliermarsh
Copy link
Member

Ah cool. We can fix this! Thanks for filing.

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