Skip to content

Conversation

@deliro
Copy link
Contributor

@deliro deliro commented Aug 5, 2025

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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+0 -1 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

zulip/zulip (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- tools/lib/provision.py:386:20: BLE001 Do not catch blind exception: `BaseException`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
BLE001 1 0 1 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -1 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

zulip/zulip (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- tools/lib/provision.py:386:20: BLE001 Do not catch blind exception: `BaseException`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
BLE001 1 0 1 0 0

@deliro deliro force-pushed the ble001-enhance branch 2 times, most recently from 66c1a31 to 84cead4 Compare August 5, 2025 09:52
@deliro deliro changed the title [flake8-blind-except] Enhance BLE001: fix docs; light speed-up; improve readability [flake8-blind-except] Fix BLE001: false-positive trigger with raise ... from None Aug 6, 2025
@ntBre ntBre self-requested a review August 8, 2025 14:08
@ntBre ntBre added bug Something isn't working rule Implementing or modifying a lint rule labels Aug 12, 2025
@ntBre ntBre linked an issue Aug 12, 2025 that may be closed by this pull request
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you! And the change in the ecosystem report is exactly like the issue.

@ntBre
Copy link
Contributor

ntBre commented Aug 12, 2025

I think the conflicts are just from recent changes to our diagnostic format. Could you just rerun the tests locally and accept the new snapshots? That's probably the easiest way to resolve them.

@deliro
Copy link
Contributor Author

deliro commented Aug 12, 2025

I think the conflicts are just from recent changes to our diagnostic format. Could you just rerun the tests locally and accept the new snapshots? That's probably the easiest way to resolve them.

Thank you! Done

@deliro deliro requested a review from ntBre August 12, 2025 20:40
@ntBre ntBre changed the title [flake8-blind-except] Fix BLE001: false-positive trigger with raise ... from None [flake8-blind-except] Fix BLE001 false-positive on raise ... from None Aug 13, 2025
@ntBre ntBre merged commit df0648a into astral-sh:main Aug 13, 2025
35 checks passed
@deliro deliro deleted the ble001-enhance branch August 13, 2025 17:49
dcreager added a commit that referenced this pull request Aug 14, 2025
* main:
  Feature/build riscv64 bin (#19819)
  [ty] Add caching to `CodeGeneratorKind::matches()` (#19912)
  [ty] Rename `functionArgumentNames` to `callArgumentNames` inlay hint setting (#19911)
  [ty] Default `ty.inlayHints.*` server settings to true (#19910)
  [ty] Remove py-fuzzer skips for seeds that are no longer slow (#19906)
  [ty] fix deferred name loading in PEP695 generic classes/functions (#19888)
  [ty] Add some additional type safety to `CycleDetector` (#19903)
  [`flake8-blind-except`] Fix `BLE001` false-positive on `raise ... from None` (#19755)
  [ty] resolve docstrings for modules (#19898)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BLE001 flags except Exception as e if re-raised from None

2 participants