Skip to content
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

Merged
merged 3 commits into from
May 20, 2023

Conversation

Bruce-8
Copy link
Contributor

@Bruce-8 Bruce-8 commented May 15, 2023

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):

  • Documentation update (change that modifies or updates documentation only)

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

  • I have performed a self-review of my own code.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported on Coveralls.

@Bruce-8 Bruce-8 marked this pull request as draft May 15, 2023 02:06
@Bruce-8 Bruce-8 marked this pull request as ready for review May 15, 2023 02:07
@Bruce-8 Bruce-8 requested a review from david-yz-liu May 15, 2023 15:42
@@ -0,0 +1,4 @@
"""Pointless Exception Statement Example"""
# The exception statement below is not raised, assigned,
Copy link
Contributor

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
Copy link
Contributor

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.


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).
Copy link
Contributor

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.

@Bruce-8 Bruce-8 requested a review from david-yz-liu May 19, 2023 03:22
@david-yz-liu david-yz-liu merged commit 78152dd into pyta-uoft:master May 20, 2023
@Bruce-8 Bruce-8 deleted the updated-document-checker-w0133 branch May 21, 2023 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants