Avoid generating dirty call paths (#2144)
This commit is contained in:
3
resources/test/fixtures/flake8_use_pathlib/use_pathlib.py
vendored
Normal file
3
resources/test/fixtures/flake8_use_pathlib/use_pathlib.py
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
from pathlib import Path
|
||||
|
||||
(Path("") / "").open()
|
||||
@@ -40,19 +40,22 @@ pub fn unparse_stmt(stmt: &Stmt, stylist: &Stylist) -> String {
|
||||
generator.generate()
|
||||
}
|
||||
|
||||
fn collect_call_path_inner<'a>(expr: &'a Expr, parts: &mut CallPath<'a>) {
|
||||
fn collect_call_path_inner<'a>(expr: &'a Expr, parts: &mut CallPath<'a>) -> bool {
|
||||
match &expr.node {
|
||||
ExprKind::Call { func, .. } => {
|
||||
collect_call_path_inner(func, parts);
|
||||
}
|
||||
ExprKind::Call { func, .. } => collect_call_path_inner(func, parts),
|
||||
ExprKind::Attribute { value, attr, .. } => {
|
||||
collect_call_path_inner(value, parts);
|
||||
parts.push(attr);
|
||||
if collect_call_path_inner(value, parts) {
|
||||
parts.push(attr);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
ExprKind::Name { id, .. } => {
|
||||
parts.push(id);
|
||||
true
|
||||
}
|
||||
_ => {}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ mod tests {
|
||||
#[test_case(Path::new("import_as.py"); "PTH1_2")]
|
||||
#[test_case(Path::new("import_from_as.py"); "PTH1_3")]
|
||||
#[test_case(Path::new("import_from.py"); "PTH1_4")]
|
||||
#[test_case(Path::new("use_pathlib.py"); "PTH1_5")]
|
||||
fn rules(path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}", path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: src/rules/flake8_use_pathlib/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
[]
|
||||
|
||||
Reference in New Issue
Block a user