Skip to content

Commit 24c0144

Browse files
dylwil3ntBre
authored andcommitted
[pylint] Stabilize ignoring __init__.py for useless-import-alias (PLC0414) (#20271)
Stabilizes change from #18400. Removed gating, updated docs, updated tests.
1 parent f726a73 commit 24c0144

File tree

5 files changed

+3
-47
lines changed

5 files changed

+3
-47
lines changed

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ pub(crate) const fn is_allow_nested_roots_enabled(settings: &LinterSettings) ->
200200
settings.preview.is_enabled()
201201
}
202202

203-
// https://github.com/astral-sh/ruff/pull/18400
204-
pub(crate) const fn is_ignore_init_files_in_useless_alias_enabled(
205-
settings: &LinterSettings,
206-
) -> bool {
207-
settings.preview.is_enabled()
208-
}
209-
210203
// https://github.com/astral-sh/ruff/pull/18572
211204
pub(crate) const fn is_optional_as_none_in_union_enabled(settings: &LinterSettings) -> bool {
212205
settings.preview.is_enabled()

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,19 +420,6 @@ mod tests {
420420
Ok(())
421421
}
422422

423-
#[test]
424-
fn preview_useless_import_alias() -> Result<()> {
425-
let diagnostics = test_path(
426-
Path::new("pylint/import_aliasing_2/__init__.py"),
427-
&LinterSettings {
428-
preview: PreviewMode::Enabled,
429-
..LinterSettings::for_rule(Rule::UselessImportAlias)
430-
},
431-
)?;
432-
assert_diagnostics!(diagnostics);
433-
Ok(())
434-
}
435-
436423
#[test]
437424
fn import_outside_top_level_with_banned() -> Result<()> {
438425
let diagnostics = test_path(

crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ use ruff_macros::{ViolationMetadata, derive_message_formats};
44
use ruff_text_size::Ranged;
55

66
use crate::checkers::ast::Checker;
7-
use crate::preview::is_ignore_init_files_in_useless_alias_enabled;
87
use crate::{Edit, Fix, FixAvailability, Violation};
98

109
/// ## What it does
1110
/// Checks for import aliases that do not rename the original package.
12-
///
13-
/// In [preview] this rule does not apply in `__init__.py` files.
11+
/// This rule does not apply in `__init__.py` files.
1412
///
1513
/// ## Why is this bad?
1614
/// The import alias is redundant and should be removed to avoid confusion.
@@ -35,8 +33,6 @@ use crate::{Edit, Fix, FixAvailability, Violation};
3533
/// ```python
3634
/// import numpy
3735
/// ```
38-
///
39-
/// [preview]: https://docs.astral.sh/ruff/preview/
4036
#[derive(ViolationMetadata)]
4137
pub(crate) struct UselessImportAlias {
4238
required_import_conflict: bool,
@@ -74,9 +70,7 @@ pub(crate) fn useless_import_alias(checker: &Checker, alias: &Alias) {
7470
}
7571

7672
// A re-export in __init__.py is probably intentional.
77-
if checker.path().ends_with("__init__.py")
78-
&& is_ignore_init_files_in_useless_alias_enabled(checker.settings())
79-
{
73+
if checker.path().ends_with("__init__.py") {
8074
return;
8175
}
8276

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
---
22
source: crates/ruff_linter/src/rules/pylint/mod.rs
33
---
4-
PLC0414 [*] Import alias does not rename original package
5-
--> __init__.py:1:8
6-
|
7-
1 | import collections as collections
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
9-
2 | from collections import OrderedDict as OrderedDict
10-
3 | from . import foo as foo
11-
|
12-
help: Remove import alias
13-
- import collections as collections
14-
1 + import collections
15-
2 | from collections import OrderedDict as OrderedDict
16-
3 | from . import foo as foo
17-
4 | from .foo import bar as bar
18-
note: This is an unsafe fix and may change runtime behavior
4+

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__preview_useless_import_alias.snap

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)