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

Forbid to raise exception from itself #2133

Closed
sobolevn opened this issue Aug 9, 2021 · 6 comments · Fixed by #2214
Closed

Forbid to raise exception from itself #2133

sobolevn opened this issue Aug 9, 2021 · 6 comments · Fixed by #2214
Assignees
Labels
good first issue Entrypoint to the project Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Milestone

Comments

@sobolevn
Copy link
Member

sobolevn commented Aug 9, 2021

Rule request

We need to forbid code like raise exc from exc, because it does not make much sense and works the same way:

>>> e = Exception('m')
>>> raise e
Traceback (most recent call last):
  File "ex.py", line 1, in <module>
    e = Exception("m"); raise e
Exception: m

And with from:

>>> e = Exception('m')
>>> raise e from e
Traceback (most recent call last):
  File "ex.py", line 1, in <module>
    e = Exception("m"); raise e
Exception: m

We need to explicitly test two cases:

  1. New raise
  2. Re-raising inside except
@sobolevn sobolevn added help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule good first issue Entrypoint to the project labels Aug 9, 2021
@sobolevn sobolevn added this to the Version 0.16 milestone Aug 9, 2021
@shruthi223
Copy link

Hi! Could you please assign me this? Im new and would like to know more!

@sobolevn
Copy link
Member Author

@shruthi223
Copy link

Hi! Been looking into the resources but since I'm a beginner, I haven't been able to make a lot of sense with it. Would it be possible to guide me on how to proceed and maybe what python file I can look at? Thanks!

@sobolevn
Copy link
Member Author

@shruthi223 sure! You need to modify this place: https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/visitors/ast/keywords.py#L54-L63

Write new _check_raise_from_itself method and a new violation inheriting ASTViolation

@singhaditya28
Copy link
Contributor

singhaditya28 commented Oct 3, 2021

Hi, I am an aspiring Hacktoberfest an OpenSource newbie. Can I take on this? and is this eligible for hacktoberfest ?

@sobolevn
Copy link
Member Author

sobolevn commented Oct 3, 2021

@singhaditya28 yes, sure! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Entrypoint to the project Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants