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
Add new checks for except (...):
clauses
#105
Conversation
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.
This is fantastic.
@@ -539,6 +578,14 @@ def visit(self, node): | |||
"to be silenced. Exceptions should be silenced in except blocks. Control " | |||
"statements can be moved outside the finally block." | |||
) | |||
B013 = Error( | |||
message="B013 A length-one tuple literal is redundant. " |
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.
I usually just say a "one-tuple".
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.
Makes sense to me, but I've left it as "length-one tuple" to minimize the terminology that new programmers need to learn (right now to use the linter).
For example I have a tox
config for formatters+linters that I encourage all my students to use when they're learning Python - in my experience automated feedback on what "good code" looks like can be really helpful, and the other bugbear messages are great at explaining why as well as what.
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.
Yup, nothing to fault here. Thanks!
I can understand both statements about the one element tuple, so up to you two there :)
Turns out that this is useful for well-linted projects too:
|
Will merge and release tonight (US Pacific time) |
When using a tuple of exception types in an
except
clause, it's easy for inexperienced Pythonistas to include elements that don't have any function at all. For example:This PR adds checks for all these cases, recommends the improved version (with
as
-clause if applicable), and thus closes #98.CC @cooperlees