mirror of https://github.com/astral-sh/ruff
Use complete symbol for `import from` (#35)
This commit is contained in:
parent
6c8794692b
commit
816bb88e3b
|
|
@ -28,7 +28,7 @@ enum BindingKind {
|
||||||
ClassDefinition,
|
ClassDefinition,
|
||||||
Definition,
|
Definition,
|
||||||
FutureImportation,
|
FutureImportation,
|
||||||
Importation,
|
Importation(String),
|
||||||
StarImportation,
|
StarImportation,
|
||||||
SubmoduleImportation,
|
SubmoduleImportation,
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +121,13 @@ impl Visitor for Checker<'_> {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
self.add_binding(Binding {
|
self.add_binding(Binding {
|
||||||
kind: BindingKind::Importation,
|
kind: BindingKind::Importation(
|
||||||
|
alias
|
||||||
|
.node
|
||||||
|
.asname
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| alias.node.name.clone()),
|
||||||
|
),
|
||||||
name: alias
|
name: alias
|
||||||
.node
|
.node
|
||||||
.asname
|
.asname
|
||||||
|
|
@ -171,11 +177,14 @@ impl Visitor for Checker<'_> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.add_binding(Binding {
|
self.add_binding(Binding {
|
||||||
kind: BindingKind::Importation,
|
kind: BindingKind::Importation(match module {
|
||||||
|
None => name.clone(),
|
||||||
|
Some(parent) => format!("{}.{}", parent, name),
|
||||||
|
}),
|
||||||
name,
|
name,
|
||||||
used: false,
|
used: false,
|
||||||
location: stmt.location,
|
location: stmt.location,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -406,8 +415,9 @@ impl Checker<'_> {
|
||||||
fn check_dead_scopes(&mut self) {
|
fn check_dead_scopes(&mut self) {
|
||||||
// TODO(charlie): Handle `__all__`.
|
// TODO(charlie): Handle `__all__`.
|
||||||
for scope in &self.dead_scopes {
|
for scope in &self.dead_scopes {
|
||||||
for (name, binding) in scope.values.iter().rev() {
|
for (_, binding) in scope.values.iter().rev() {
|
||||||
if !binding.used && matches!(binding.kind, BindingKind::Importation) {
|
if !binding.used {
|
||||||
|
if let BindingKind::Importation(name) = &binding.kind {
|
||||||
self.checks.push(Check {
|
self.checks.push(Check {
|
||||||
kind: CheckKind::UnusedImport(name.clone()),
|
kind: CheckKind::UnusedImport(name.clone()),
|
||||||
location: binding.location,
|
location: binding.location,
|
||||||
|
|
@ -416,6 +426,7 @@ impl Checker<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_ast(python_ast: &Suite, settings: &Settings) -> Vec<Check> {
|
pub fn check_ast(python_ast: &Suite, settings: &Settings) -> Vec<Check> {
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ mod tests {
|
||||||
filename: "./resources/test/src/F401.py".to_string(),
|
filename: "./resources/test/src/F401.py".to_string(),
|
||||||
},
|
},
|
||||||
Message {
|
Message {
|
||||||
kind: CheckKind::UnusedImport("OrderedDict".to_string()),
|
kind: CheckKind::UnusedImport("collections.OrderedDict".to_string()),
|
||||||
location: Location::new(3, 1),
|
location: Location::new(3, 1),
|
||||||
filename: "./resources/test/src/F401.py".to_string(),
|
filename: "./resources/test/src/F401.py".to_string(),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue