-
Notifications
You must be signed in to change notification settings - Fork 11
Add try/except/finally complexity rules #12
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
Conversation
| with self.assertAddsMessages( | ||
| pylint.testutils.Message('finally-too-long', node=root.body[0], args={'found': 24}), | ||
| pylint.testutils.Message('try-too-long', node=root.body[0].body[0], args={'found': 28}), | ||
| pylint.testutils.Message('except-too-long', node=root.body[0].body[0].handlers[0], |
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.
Could you name these nodes something more meaningful, so the reader can know what root.body[0].body[0].handlers[0] refers to without parsing the tree?
| pylint.testutils.Message('finally-too-long', node=root.body[0], args={'found': 24}), | ||
| pylint.testutils.Message('try-too-long', node=root.body[0].body[0], args={'found': 28}), | ||
| pylint.testutils.Message('except-too-long', node=root.body[0].body[0].handlers[0], | ||
| args={'found': 39}), |
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.
Hard-coding these specific values make this test a little fragile, leaning on the specific implementation of count_tree_size. Is there any way to test that the messages were thrown with a value, not necessarily this specific value?
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.
It's tied specifically to the value of the test input, which is unlikely to change without the test input also changing. I think it's fine to be really specific here.
|
Minor comments about one of the tests, otherwise LGTM |
|
LGTM too pending @JasonMWhite's comments |
7d9fc55 to
a25a373
Compare
This PR tries to measure the complexity of
try/except/finallyblocks in terms of the number of AST nodes within the body of each statement. The goal of these rules is to encourage less code (not simply measured in lines) within these sections.– Google Python Styleguide
Running this on a large codebase we get no parse errors and by setting the max length to zero we also get some statistics on body tree sizes in nodes:
Assuming that the 80% of this large project's try/except/finally blocks are appropriate, the default block sizes could be set to 25, 23, and 13 respectively.