mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-03 05:13:00 +00:00
[flake8-blind-except] Fix BLE001 false-positive on raise ... from None (#19755)
## Summary
- Refactored `BLE001` logic for clarity and minor speed-up.
- Improved documentation and comments (previously, `BLE001` docs claimed
it catches bare `except:`s, but it doesn't).
- Fixed a false-positive bug with `from None` cause:
```python
# somefile.py
try:
pass
except BaseException as e:
raise e from None
```
### main branch
```
somefile.py:3:8: BLE001 Do not catch blind exception: `BaseException`
|
1 | try:
2 | pass
3 | except BaseException as e:
| ^^^^^^^^^^^^^ BLE001
4 | raise e from None
|
Found 1 error.
```
### this change
```cargo run -p ruff -- check somefile.py --no-cache --select=BLE001```
```
All checks passed!
```
## Test Plan
- Added a test case to cover `raise X from Y` clause
- Added a test case to cover `raise X from None` clause
This commit is contained in:
parent
f0b03c3e86
commit
df0648aae0
3 changed files with 88 additions and 70 deletions
|
|
@ -154,6 +154,11 @@ try:
|
|||
except Exception as e:
|
||||
raise ValueError from e
|
||||
|
||||
try:
|
||||
...
|
||||
except Exception as e:
|
||||
raise e from ValueError("hello")
|
||||
|
||||
|
||||
try:
|
||||
pass
|
||||
|
|
@ -245,3 +250,9 @@ try:
|
|||
pass
|
||||
except (Exception, ValueError) as e:
|
||||
raise e
|
||||
|
||||
# `from None` cause
|
||||
try:
|
||||
pass
|
||||
except BaseException as e:
|
||||
raise e from None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue