-
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
Introduce B030; fix crash on weird except handlers #346
Conversation
haha - I always feel bad when I push something somewhere and black is upset at my formatting! I can try fix before merge eventually too if you don't beat me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks mate. One of us can just fix the formatting.
Looks like you just merged a different B029 so there's a little more work to do :) I turned off my editor's format-on-save because it's annoying when writing test cases for Black, lol. Should probably figure out a way to keep it on for other projects. |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
All green now. |
LGTM, but do we also want to allow function calls (by allowing ast.Call)? For example: def exceptions():
return ValueError, KeyError
try:
pass
except exceptions():
pass Not entirely sure how common it is, and we obviously can't check the return values of the function, but I think it'd still be useful for some use cases. |
I guess we could allow it. People could also plausibly write @cooperlees what do you think, should we allow calls in except handlers? |
That's a good point. I think we definitely want to identify that |
This is a strange pattern, but I am sure valid. Is there any harm doing a function call here? I don't see any so probably best we handle this edge case ... But happy for another PR to do that ... Was going to release a new version later today. |
What Jelle mentioned above, def exceptions():
return ValueError, KeyError
try:
pass
except exceptions():
pass I think that we would want to catch the |
Yeah, lets see if it's a common pattern (via issues opened) and if so address it then. Thanks again all! |
Fixes #345.
This introduces a new bugbear check against things like
except call():
orexcept 1:
. This could be legitimate code (if you have a function that returns an exception class), but I'm not sure that's something that would ever come up in practice.bugbear would previously crash on any except handler that is not a Tuple, Name, Attribute, or Call.