Skip to content

Commit

Permalink
Avoid F401 panic with noqa import name (#7260)
Browse files Browse the repository at this point in the history
Closes #7244.
  • Loading branch information
charliermarsh authored Sep 10, 2023
1 parent 69d0caa commit 0357e80
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions crates/ruff/resources/test/fixtures/pyflakes/F401_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ def b(self) -> None:
import b1

import b2


# Regression test for: https://github.com/astral-sh/ruff/issues/7244
from datameta_client_lib.model_utils import ( # noqa: F401
noqa )

from datameta_client_lib.model_helpers import (
noqa )
2 changes: 1 addition & 1 deletion crates/ruff/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a> Directive<'a> {
if text[..comment_start]
.chars()
.last()
.is_some_and(|c| c != '#')
.map_or(true, |c| c != '#')
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ F401_0.py:112:16: F401 [*] `b1` imported but unused
112 |- import b1
113 112 |
114 113 | import b2
115 114 |

F401_0.py:114:16: F401 [*] `b2` imported but unused
|
Expand All @@ -263,5 +264,23 @@ F401_0.py:114:16: F401 [*] `b2` imported but unused
112 112 | import b1
113 113 |
114 |- import b2
115 114 |
116 115 |
117 116 | # Regression test for: https://github.com/astral-sh/ruff/issues/7244

F401_0.py:122:1: F401 [*] `datameta_client_lib.model_helpers.noqa` imported but unused
|
121 | from datameta_client_lib.model_helpers import (
122 | noqa )
| ^^^^ F401
|
= help: Remove unused import: `datameta_client_lib.model_helpers.noqa`

Fix
118 118 | from datameta_client_lib.model_utils import ( # noqa: F401
119 119 | noqa )
120 120 |
121 |-from datameta_client_lib.model_helpers import (
122 |-noqa )


0 comments on commit 0357e80

Please sign in to comment.