Skip to content

Commit a29f484

Browse files
committed
Fix failing test
1 parent 416e985 commit a29f484

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

crates/ruff_linter/src/rules/pyflakes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ mod tests {
244244
fn f401_preview_first_party_submodule(contents: &str, snapshot: &str) {
245245
let diagnostics = test_contents(
246246
&SourceKind::Python(dedent(contents).to_string()),
247-
Path::new("__init__.py"),
247+
Path::new("f401_preview_first_party_submodule/__init__.py"),
248248
&LinterSettings {
249249
preview: PreviewMode::Enabled,
250250
isort: isort::settings::Settings {

crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
305305
.map(|binding| {
306306
let context = if in_except_handler {
307307
Some(UnusedImportContext::ExceptHandler)
308-
} else if in_init {
308+
} else if in_init && !binding.import.is_submodule_import() {
309309
Some(UnusedImportContext::Init {
310310
first_party: is_first_party(
311311
&binding.import.qualified_name().to_string(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: crates/ruff_linter/src/rules/pyflakes/mod.rs
3+
---
4+
__init__.py:2:8: F401 [*] `submodule.a` imported but unused
5+
|
6+
2 | import submodule.a
7+
| ^^^^^^^^^^^ F401
8+
3 | __all__ = ['FOO']
9+
4 | FOO = 42
10+
|
11+
= help: Remove unused import: `submodule.a`
12+
13+
Unsafe fix
14+
1 1 |
15+
2 |-import submodule.a
16+
3 2 | __all__ = ['FOO']
17+
4 3 | FOO = 42

0 commit comments

Comments
 (0)