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.
False positive B023 errors are quite common with
filter,reduce,key=,returnandmap. For instance, this codeis 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
filterormapis not evaluated before the next iteration, but this was deemed acceptable in the Bugbear issue.