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

Fix some B023 false alarms #303

Merged
merged 5 commits into from Oct 25, 2022
Merged

Fix some B023 false alarms #303

merged 5 commits into from Oct 25, 2022

Conversation

jakkdl
Copy link
Contributor

@jakkdl jakkdl commented Oct 25, 2022

Picking up from main...Zac-HD:flake8-bugbear:B023-false-alarms
Partially fixes #269

Fixes some common false alarms where a function is immediately consumed, as an argument to filter or reduce, as a keyword argument to key= and as a return value.

TODO: I'm not sure how to handle more complex return cases, see the last test cases in b023.py.

I'm also not sure if this solution is too generous, it currently marks all direct child nodes to calls to filter&reduce as safe - but @Zac-HD's comment implies it should maybe be stricter:

Unfortunately it's more difficult to avoid this false alarm than you might think: for example "lambdas are OK if they're the first argument in a call to filter()" would miss bugs where the filter iterable (and therefore lambda) isn't immediately evaluated.

I'm not super read up on the problem and didn't take time to fully understand all comments with false alarms in the original issue, so would love some eyes on this. But it fixes all test cases @Zac-HD added at least.

Copy link
Member

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - thanks @jakkdl!

cc @cooperlees to merge?

@cooperlees
Copy link
Collaborator

Thanks. Lots going on here I don't get but I'll trust you two! Tests look good.

@cooperlees cooperlees merged commit e16ad24 into PyCQA:main Oct 25, 2022
@Zac-HD
Copy link
Member

Zac-HD commented Oct 25, 2022

I'm also not sure if this solution is too generous, it currently marks all direct child nodes to calls to filter&reduce as safe - but @Zac-HD's comment implies it should maybe be stricter:

Unfortunately it's more difficult to avoid this false alarm than you might think: for example "lambdas are OK if they're the first argument in a call to filter()" would miss bugs where the filter iterable (and therefore lambda) isn't immediately evaluated.

In short, there was enough chatter in that thread to make it clear the false-alarm rate was unacceptably high, and if we miss some real alarms that's basically just the natural downside of minimally-resourced open source projects! Better to catch most bugs without annoying people than have a tool that nobody uses...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

B023 false alarms
3 participants