ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Unused `noqa` directive (unused: `BLE001`) wrongly detected

Open revliscano opened this issue 1 year ago • 3 comments

After upgrading to version 0.4.4, Ruff analysis is failing for this code

try:
    ...
except Exception as e:  # noqa: BLE001
    ...

When I run:

$ pip install ruff==0.4.4
$ ruff check .
emails/backend.py:49:33: RUF100 [*] Unused `noqa` directive (unused: `BLE001`)

It says that BLE001 is unused, when it's clearly necessary there. In the previous ruff version (0.4.3) this was not happening.

Edit

I'm including the rest of the except block, as requested by @charliermarsh

try:
   ...
except Exception as e:  # noqa: BLE001
    if not self.fail_silently:
        raise e

revliscano avatar May 10 '24 12:05 revliscano

Can you include the rest of the except block? We don't flag BLE if the exception is re-raised or logged. We fixed a bug and removed some false positives, which might explain what you're seeing.

charliermarsh avatar May 10 '24 13:05 charliermarsh

Yeah, my PR was not perfect, it also accepts it when the re-raise only happens inside an if (see https://github.com/home-assistant/core/pull/117166#discussion_r1596329890 ) We will need to add a checker if all codepaths re-raise and/or log.

autinerd avatar May 10 '24 15:05 autinerd

Can you include the rest of the except block? We don't flag BLE if the exception is re-raised or logged. We fixed a bug and removed some false positives, which might explain what you're seeing.

I edited the description of the issue to include the rest of the except block.

And yes, we were re-raising the exception indeed.

revliscano avatar May 10 '24 17:05 revliscano

I think this is working as intended personally. If you're re-raising the exception, the assumption is that you're catching this intentionally.

charliermarsh avatar May 22 '24 02:05 charliermarsh