-
Notifications
You must be signed in to change notification settings - Fork 59
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
Added documentation and example of W0133 Pointless Exception Statement Checker #898
Added documentation and example of W0133 Pointless Exception Statement Checker #898
Conversation
@@ -0,0 +1,4 @@ | |||
"""Pointless Exception Statement Example""" | |||
# The exception statement below is not raised, assigned, |
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.
Just say "The exception below", the word 'statement' is a bit misleading since it's really the expression that isn't being used
"""Pointless Exception Statement Example""" | ||
# The exception statement below is not raised, assigned, | ||
# or returned for use anywhere in this file. | ||
Exception("This is a pointless exception statement.") # Error on this line |
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.
Let's make this example a bit more realistic. Can you try something like the following (but please run pylint/PythonTA to make sure it actually triggers the error!):
def reciprocal(x: float) -> float:
"""Return 1 / x."""
if x == 0:
ValueError('x cannot be zero') # Error on this line
else:
return 1 / x
and then in the documentation, show how to fix the error.
docs/checkers/index.md
Outdated
|
||
This error can be resolved by assigning, raising or returning the exception as demonstrated below: | ||
|
||
**Note** : NameError is a subclass of Exception (it is a more specific type of exception in Python). |
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.
Based on the changes I've described below, you can remove this sentence.
Motivation and Context
Checker W0133 (pointless-exception-statement) is one of the new checkers that recently got added to PythonTA. The changes made in this pull request provide a description for checker W0133 to ensure informed and proper usage.
Your Changes
Description: Added documentation of checker W0133 (pointless-exception-statement), created an example to display how error W0133 is triggered, and provided a correction to the example code that demonstrates how to resolve error W0133.
Type of change (select all that apply):
Testing
Used a pylint scanner to ensure the example code emits and the correction resolves error W0133. Proofread the documentation of checker W0133 to ensure that the explanation is beginner-friendly and correct.
Questions and Comments (if applicable)
Checklist