ruff icon indicating copy to clipboard operation
ruff copied to clipboard

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

Open autinerd opened this issue 10 months ago • 2 comments

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!

autinerd avatar Apr 06 '24 18:04 autinerd

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 avatar Apr 07 '24 03:04 charliermarsh

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.

autinerd avatar Apr 07 '24 03:04 autinerd