astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.

Home Page:https://docs.astral.sh/ruff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

revliscano opened this issue · 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

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.

commented

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

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.

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