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

[flake8-blind-expect] Allow raise ... from ex in except Exception as ex in BLE001 #10806

Closed
autinerd opened this issue Apr 6, 2024 · 2 comments · Fixed by #11131
Closed

[flake8-blind-expect] Allow raise ... from ex in except Exception as ex in BLE001 #10806

autinerd opened this issue Apr 6, 2024 · 2 comments · Fixed by #11131
Labels
accepted Ready for implementation rule Implementing or modifying a lint rule

Comments

@autinerd
Copy link
Contributor

autinerd commented Apr 6, 2024

Hi,

currently this is allowed in BLE001:

try:
    ...
except Exception:
    raise

But it may be a good idea to allow this format as well (as pylint broad-exception-caught does):

try:
    ...
except Exception as ex:
     raise ValueError from ex

Thanks in advance!

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer bug Something isn't working and removed needs-decision Awaiting a decision from a maintainer labels Apr 7, 2024
@charliermarsh
Copy link
Member

Yeah, I would say that should be allowed. (There are other rules in Ruff that would then suggest you remove the redundant alias, but on its own it's within the bounds of BLE001 to allow this IMO.)

@charliermarsh charliermarsh added accepted Ready for implementation and removed bug Something isn't working labels Apr 7, 2024
@autinerd
Copy link
Contributor Author

autinerd commented Apr 7, 2024

Thanks!

The variable is only redundant when it is used in raise ex (TRY201) or in logging.exception() (TRY401), but in raise ... from ex it is needed.

charliermarsh pushed a commit that referenced this issue Apr 24, 2024
## Summary

This allows `raise from` in BLE001.

```python
try:
    ...
except Exception as e:
    raise ValueError from e
```

Fixes #10806

## Test Plan

Test case added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants