mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 22:10:48 -05:00
Avoid wrapping import-star statements (#1089)
This commit is contained in:
@@ -42,6 +42,15 @@ pub fn format_import_from(
|
||||
force_wrap_aliases: bool,
|
||||
is_first: bool,
|
||||
) -> String {
|
||||
if aliases.len() == 1
|
||||
&& aliases
|
||||
.iter()
|
||||
.all(|(alias, _)| alias.name == "*" && alias.asname.is_none())
|
||||
{
|
||||
let (single_line, ..) = format_single_line(import_from, comments, aliases, is_first);
|
||||
return single_line;
|
||||
}
|
||||
|
||||
// We can only inline if: (1) none of the aliases have atop comments, and (3)
|
||||
// only the last alias (if any) has inline comments.
|
||||
if aliases
|
||||
@@ -58,7 +67,7 @@ pub fn format_import_from(
|
||||
{
|
||||
let (single_line, import_length) =
|
||||
format_single_line(import_from, comments, aliases, is_first);
|
||||
if import_length <= line_length {
|
||||
if import_length <= line_length || aliases.iter().any(|(alias, _)| alias.name == "*") {
|
||||
return single_line;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,6 +561,7 @@ mod tests {
|
||||
#[test_case(Path::new("insert_empty_lines.py"))]
|
||||
#[test_case(Path::new("leading_prefix.py"))]
|
||||
#[test_case(Path::new("no_reorder_within_section.py"))]
|
||||
#[test_case(Path::new("no_wrap_star.py"))]
|
||||
#[test_case(Path::new("order_by_type.py"))]
|
||||
#[test_case(Path::new("order_relative_imports_by_level.py"))]
|
||||
#[test_case(Path::new("preserve_comment_order.py"))]
|
||||
|
||||
20
src/isort/snapshots/ruff__isort__tests__no_wrap_star.py.snap
Normal file
20
src/isort/snapshots/ruff__isort__tests__no_wrap_star.py.snap
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
source: src/isort/mod.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: UnsortedImports
|
||||
location:
|
||||
row: 1
|
||||
column: 0
|
||||
end_location:
|
||||
row: 2
|
||||
column: 0
|
||||
fix:
|
||||
content: "from .subscription import * # type: ignore # some very long comment explaining why this needs a type ignore\n"
|
||||
location:
|
||||
row: 1
|
||||
column: 0
|
||||
end_location:
|
||||
row: 2
|
||||
column: 0
|
||||
|
||||
Reference in New Issue
Block a user