Introduce B030; fix crash on weird except handlers#346
Introduce B030; fix crash on weird except handlers#346cooperlees merged 5 commits intoPyCQA:mainfrom
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. |
cooperlees
left a comment
There was a problem hiding this comment.
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():
passNot 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():
passI 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.