Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused noqa directive (unused: BLE001) wrongly detected #11360

Closed
revliscano opened this issue May 10, 2024 · 4 comments
Closed

Unused noqa directive (unused: BLE001) wrongly detected #11360

revliscano opened this issue May 10, 2024 · 4 comments
Labels
question Asking for support or clarification

Comments

@revliscano
Copy link

revliscano commented May 10, 2024

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
@charliermarsh
Copy link
Member

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 charliermarsh added the question Asking for support or clarification label May 10, 2024
@autinerd
Copy link
Contributor

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.

@revliscano
Copy link
Author

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.

@charliermarsh
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants