Skip to content

B023 False positives #1686

@TomFryers

Description

@TomFryers

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.

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