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

0.7.3 introduces false positives for invalid # noqa directives with RUF100 #14228

Closed
BryceBeagle opened this issue Nov 9, 2024 · 5 comments · Fixed by #14229
Closed

0.7.3 introduces false positives for invalid # noqa directives with RUF100 #14228

BryceBeagle opened this issue Nov 9, 2024 · 5 comments · Fixed by #14229
Assignees
Labels
bug Something isn't working

Comments

@BryceBeagle
Copy link

BryceBeagle commented Nov 9, 2024

I'm working on upgrading our codebase to use ruff=0.7.3, but there are some RUF100 changes that start flagging
some comments as being "Unused noqa directive"s.

I'm not sure if this is intentional (perhaps there's a sanctioned way of adding a comment we're not using?), but this feels like a regression to me.

This doesn't happen in 0.7.2.
I'm assuming this is related to #12809

Examples:

--- blah.py
+++ blah.py
@@ -118,7 +118,7 @@
                     if res is not None:
                         res.release()

-                if 200 <= res.status < 300:  # noqa: PLR2004 Use raise_for_status
+                if 200 <= res.status < 300:  # noqa: PLR2004 raise_for_status
                     return
                 if (
                     res.status not in self._retry_status_codes

Would fix 1 error.
--- foobar.py
+++ foobar.py
@@ -43,7 +43,7 @@

     @inject
     def download(self) -> Any:
-        temp_file = tempfile.NamedTemporaryFile(suffix=".tar.gz", delete=False)  # noqa: SIM115 Closing right below
+        temp_file = tempfile.NamedTemporaryFile(suffix=".tar.gz", delete=False)  # noqa: SIM115 right below
         temp_file.close()

         key = f"{self.base_commit}.tar.gz"

Would fix 1 error.
--- fake_name.py
+++ fake_name.py
@@ -47,7 +47,7 @@
         applied_manifests
     )

-    manifest_yaml_file = tempfile.NamedTemporaryFile(  # noqa: SIM115 We're closing the file below
+    manifest_yaml_file = tempfile.NamedTemporaryFile(  # noqa: SIM115're closing the file below
         prefix="manifest_yaml_", delete=False
     )
     manifest_yaml_file.close()
blah.py:121:46: RUF100 [*] Unused `noqa` directive (unknown: `Use`)
foobar.py:46:82: RUF100 [*] Unused `noqa` directive (unknown: `Closing`)
fake_name:50:56: RUF100 [*] Unused `noqa` directive (unknown: `We`)     
@charliermarsh
Copy link
Member

Yeah definitely, sorry about that.

@charliermarsh charliermarsh self-assigned this Nov 9, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Nov 9, 2024
@charliermarsh
Copy link
Member

(You can probably work around it for now by adding a # in between, like: # noqa: SIM115 # We're closing the file below or # noqa: SIM115 - We're closing the file below).

@BryceBeagle
Copy link
Author

Is adding a # recommended in general? Happy to update our pragmas to align with a recommended standard, if there is one

@charliermarsh
Copy link
Member

I tend to do it because it disambiguates the content from the pragma (and it's easier for us to parse without any ambiguity). It's also nice if you have multiple pragmas on the same line, like # noqa # type: ignore or something. But I don't know that it's an "official" recommendation :)

charliermarsh added a commit that referenced this issue Nov 9, 2024
## Summary

An oversight from the original implementation.

Closes #14228.
@BryceBeagle
Copy link
Author

Thanks so much for the rapid fix! You're awesome 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants