mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:35 +00:00
Replace &String with &str in AnnotatedImport::ImportFrom (#1674)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
914287d31b
commit
1ad72261f1
1 changed files with 11 additions and 30 deletions
|
@ -46,7 +46,7 @@ pub enum AnnotatedImport<'a> {
|
||||||
inline: Vec<Comment<'a>>,
|
inline: Vec<Comment<'a>>,
|
||||||
},
|
},
|
||||||
ImportFrom {
|
ImportFrom {
|
||||||
module: Option<&'a String>,
|
module: Option<&'a str>,
|
||||||
names: Vec<AnnotatedAliasData<'a>>,
|
names: Vec<AnnotatedAliasData<'a>>,
|
||||||
level: Option<&'a usize>,
|
level: Option<&'a usize>,
|
||||||
atop: Vec<Comment<'a>>,
|
atop: Vec<Comment<'a>>,
|
||||||
|
@ -152,7 +152,7 @@ fn annotate_imports<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
annotated.push(AnnotatedImport::ImportFrom {
|
annotated.push(AnnotatedImport::ImportFrom {
|
||||||
module: module.as_ref(),
|
module: module.as_deref(),
|
||||||
names: aliases,
|
names: aliases,
|
||||||
level: level.as_ref(),
|
level: level.as_ref(),
|
||||||
trailing_comma: if split_on_trailing_comma {
|
trailing_comma: if split_on_trailing_comma {
|
||||||
|
@ -219,28 +219,19 @@ fn normalize_imports(imports: Vec<AnnotatedImport>, combine_as_imports: bool) ->
|
||||||
let entry = if alias.name == "*" {
|
let entry = if alias.name == "*" {
|
||||||
block
|
block
|
||||||
.import_from_star
|
.import_from_star
|
||||||
.entry(ImportFromData {
|
.entry(ImportFromData { module, level })
|
||||||
module: module.map(String::as_str),
|
|
||||||
level,
|
|
||||||
})
|
|
||||||
.or_default()
|
.or_default()
|
||||||
} else if alias.asname.is_none() || combine_as_imports {
|
} else if alias.asname.is_none() || combine_as_imports {
|
||||||
&mut block
|
&mut block
|
||||||
.import_from
|
.import_from
|
||||||
.entry(ImportFromData {
|
.entry(ImportFromData { module, level })
|
||||||
module: module.map(String::as_str),
|
|
||||||
level,
|
|
||||||
})
|
|
||||||
.or_default()
|
.or_default()
|
||||||
.0
|
.0
|
||||||
} else {
|
} else {
|
||||||
block
|
block
|
||||||
.import_from_as
|
.import_from_as
|
||||||
.entry((
|
.entry((
|
||||||
ImportFromData {
|
ImportFromData { module, level },
|
||||||
module: module.map(String::as_str),
|
|
||||||
level,
|
|
||||||
},
|
|
||||||
AliasData {
|
AliasData {
|
||||||
name: alias.name,
|
name: alias.name,
|
||||||
asname: alias.asname,
|
asname: alias.asname,
|
||||||
|
@ -263,18 +254,12 @@ fn normalize_imports(imports: Vec<AnnotatedImport>, combine_as_imports: bool) ->
|
||||||
let entry = if alias.name == "*" {
|
let entry = if alias.name == "*" {
|
||||||
block
|
block
|
||||||
.import_from_star
|
.import_from_star
|
||||||
.entry(ImportFromData {
|
.entry(ImportFromData { module, level })
|
||||||
module: module.map(String::as_str),
|
|
||||||
level,
|
|
||||||
})
|
|
||||||
.or_default()
|
.or_default()
|
||||||
} else if alias.asname.is_none() || combine_as_imports {
|
} else if alias.asname.is_none() || combine_as_imports {
|
||||||
block
|
block
|
||||||
.import_from
|
.import_from
|
||||||
.entry(ImportFromData {
|
.entry(ImportFromData { module, level })
|
||||||
module: module.map(String::as_str),
|
|
||||||
level,
|
|
||||||
})
|
|
||||||
.or_default()
|
.or_default()
|
||||||
.1
|
.1
|
||||||
.entry(AliasData {
|
.entry(AliasData {
|
||||||
|
@ -286,10 +271,7 @@ fn normalize_imports(imports: Vec<AnnotatedImport>, combine_as_imports: bool) ->
|
||||||
block
|
block
|
||||||
.import_from_as
|
.import_from_as
|
||||||
.entry((
|
.entry((
|
||||||
ImportFromData {
|
ImportFromData { module, level },
|
||||||
module: module.map(String::as_str),
|
|
||||||
level,
|
|
||||||
},
|
|
||||||
AliasData {
|
AliasData {
|
||||||
name: alias.name,
|
name: alias.name,
|
||||||
asname: alias.asname,
|
asname: alias.asname,
|
||||||
|
@ -308,10 +290,9 @@ fn normalize_imports(imports: Vec<AnnotatedImport>, combine_as_imports: bool) ->
|
||||||
|
|
||||||
// Propagate trailing commas.
|
// Propagate trailing commas.
|
||||||
if matches!(trailing_comma, TrailingComma::Present) {
|
if matches!(trailing_comma, TrailingComma::Present) {
|
||||||
if let Some(entry) = block.import_from.get_mut(&ImportFromData {
|
if let Some(entry) =
|
||||||
module: module.map(String::as_str),
|
block.import_from.get_mut(&ImportFromData { module, level })
|
||||||
level,
|
{
|
||||||
}) {
|
|
||||||
entry.2 = trailing_comma;
|
entry.2 = trailing_comma;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue