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

Various rules refer to except* as except #14791

Closed
jakkdl opened this issue Dec 5, 2024 · 4 comments · Fixed by #14815
Closed

Various rules refer to except* as except #14791

jakkdl opened this issue Dec 5, 2024 · 4 comments · Fixed by #14815
Assignees
Labels
diagnostics Related to reporting of diagnostics. good first issue Good for newcomers help wanted Contributions especially welcome

Comments

@jakkdl
Copy link

jakkdl commented Dec 5, 2024

I did a pass on all flake8-bugbear rules upstream to check for except* handling (PyCQA/flake8-bugbear#500), and then also checked ruff.. which already handles all of them 🥳 But a bunch of them assume except in their message, which could perhaps be confusing to users - but tbh it's mostly a nitpick.

I have not checked any rules other than flake8-bugbear, so I suggest you do a pass checking for any other rules that might be referring to except.

try:
    a = 1
except* ValueError:
    a = 2
except* ValueError:
    a = 2

try:
    pass
except* ():
    pass

try:
    pass
except* 1:  # error
    pass

try:
    raise ValueError
except* ValueError:
    raise UserWarning
$ ruff check --select=B foo.py
foo.py:6:9: B025 try-except block with duplicate exception `ValueError`
foo.py:11:1: B029 Using `except ():` with an empty tuple does not catch anything; add exceptions to handle
foo.py:16:9: B030 `except` handlers should only be exception classes or tuples of exception classes
foo.py:22:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
Found 4 errors.

expected output

$ ruff check --select=B foo.py
foo.py:6:9: B025 try-except* block with duplicate exception `ValueError`
foo.py:11:1: B029 Using `except* ():` with an empty tuple does not catch anything; add exceptions to handle
foo.py:16:9: B030 `except*` handlers should only be exception classes or tuples of exception classes
foo.py:22:5: B904 Within an `except*` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling
Found 4 errors.
@dylwil3 dylwil3 added the diagnostics Related to reporting of diagnostics. label Dec 5, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Dec 5, 2024

Thanks for the audit and write-up! This seems reasonable to me to try to fix.

@dylwil3 dylwil3 added help wanted Contributions especially welcome good first issue Good for newcomers labels Dec 5, 2024
@smokyabdulrahman
Copy link
Contributor

I can take this if it's available 👌

@smokyabdulrahman
Copy link
Contributor

Draft PR opened.
You can comment anytime if my approach doesn't meet the standard of astral-sh or rust.

P.S. It's my first rust code base contribution.

@smokyabdulrahman
Copy link
Contributor

PR Ready for Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Related to reporting of diagnostics. good first issue Good for newcomers help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants