mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
Update RustPython to get main versions of end_location etc. (#445)
This commit is contained in:
parent
cf0d198365
commit
edefa5219c
15 changed files with 34 additions and 35 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -2101,7 +2101,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rustpython-ast"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=210db77e4274787028dc3ebc0b4841d1334c8c10#210db77e4274787028dc3ebc0b4841d1334c8c10"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=1b253a12705f84972cd76e8dc1cdaaccb233e5a5#1b253a12705f84972cd76e8dc1cdaaccb233e5a5"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"rustpython-common",
|
||||
|
@ -2111,7 +2111,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rustpython-common"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=210db77e4274787028dc3ebc0b4841d1334c8c10#210db77e4274787028dc3ebc0b4841d1334c8c10"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=1b253a12705f84972cd76e8dc1cdaaccb233e5a5#1b253a12705f84972cd76e8dc1cdaaccb233e5a5"
|
||||
dependencies = [
|
||||
"ascii",
|
||||
"cfg-if 1.0.0",
|
||||
|
@ -2134,7 +2134,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rustpython-compiler-core"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=210db77e4274787028dc3ebc0b4841d1334c8c10#210db77e4274787028dc3ebc0b4841d1334c8c10"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=1b253a12705f84972cd76e8dc1cdaaccb233e5a5#1b253a12705f84972cd76e8dc1cdaaccb233e5a5"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bitflags",
|
||||
|
@ -2151,7 +2151,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "rustpython-parser"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=210db77e4274787028dc3ebc0b4841d1334c8c10#210db77e4274787028dc3ebc0b4841d1334c8c10"
|
||||
source = "git+https://github.com/charliermarsh/RustPython.git?rev=1b253a12705f84972cd76e8dc1cdaaccb233e5a5#1b253a12705f84972cd76e8dc1cdaaccb233e5a5"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
|
|
|
@ -26,9 +26,9 @@ once_cell = { version = "1.13.1" }
|
|||
path-absolutize = { version = "3.0.14", features = ["once_cell_cache", "use_unix_paths_on_wasm"] }
|
||||
rayon = { version = "1.5.3" }
|
||||
regex = { version = "1.6.0" }
|
||||
rustpython-ast = { features = ["unparse"], git = "https://github.com/charliermarsh/RustPython.git", rev = "210db77e4274787028dc3ebc0b4841d1334c8c10" }
|
||||
rustpython-common = { git = "https://github.com/charliermarsh/RustPython.git", rev = "210db77e4274787028dc3ebc0b4841d1334c8c10" }
|
||||
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/charliermarsh/RustPython.git", rev = "210db77e4274787028dc3ebc0b4841d1334c8c10" }
|
||||
rustpython-ast = { features = ["unparse"], git = "https://github.com/charliermarsh/RustPython.git", rev = "1b253a12705f84972cd76e8dc1cdaaccb233e5a5" }
|
||||
rustpython-common = { git = "https://github.com/charliermarsh/RustPython.git", rev = "1b253a12705f84972cd76e8dc1cdaaccb233e5a5" }
|
||||
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/charliermarsh/RustPython.git", rev = "1b253a12705f84972cd76e8dc1cdaaccb233e5a5" }
|
||||
serde = { version = "1.0.143", features = ["derive"] }
|
||||
serde_json = { version = "1.0.83" }
|
||||
strum = { version = "0.24.1", features = ["strum_macros"] }
|
||||
|
|
|
@ -4,14 +4,14 @@ use crate::ast::types::Range;
|
|||
|
||||
fn relocate_keyword(keyword: &mut Keyword, location: Range) {
|
||||
keyword.location = location.location;
|
||||
keyword.end_location = location.end_location;
|
||||
keyword.end_location = Some(location.end_location);
|
||||
relocate_expr(&mut keyword.node.value, location);
|
||||
}
|
||||
|
||||
/// Change an expression's location (recursively) to match a desired, fixed location.
|
||||
pub fn relocate_expr(expr: &mut Expr, location: Range) {
|
||||
expr.location = location.location;
|
||||
expr.end_location = location.end_location;
|
||||
expr.end_location = Some(location.end_location);
|
||||
match &mut expr.node {
|
||||
ExprKind::BoolOp { values, .. } => {
|
||||
for expr in values {
|
||||
|
|
|
@ -18,7 +18,9 @@ impl Range {
|
|||
pub fn from_located<T>(located: &Located<T>) -> Self {
|
||||
Range {
|
||||
location: located.location,
|
||||
end_location: located.end_location,
|
||||
end_location: located
|
||||
.end_location
|
||||
.expect("AST nodes should have end_location."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ pub fn remove_stmt(stmt: &Stmt, parent: Option<&Stmt>, deleted: &[&Stmt]) -> Res
|
|||
// it with a `pass`.
|
||||
Ok(Fix {
|
||||
location: stmt.location,
|
||||
end_location: stmt.end_location,
|
||||
end_location: stmt.end_location.unwrap(),
|
||||
content: "pass".to_string(),
|
||||
applied: false,
|
||||
})
|
||||
|
@ -243,7 +243,7 @@ pub fn remove_stmt(stmt: &Stmt, parent: Option<&Stmt>, deleted: &[&Stmt]) -> Res
|
|||
// TODO(charlie): This logic assumes that there are no multi-statement physical lines.
|
||||
Ok(Fix {
|
||||
location: Location::new(stmt.location.row(), 1),
|
||||
end_location: Location::new(stmt.end_location.row() + 1, 1),
|
||||
end_location: Location::new(stmt.end_location.unwrap().row() + 1, 1),
|
||||
content: "".to_string(),
|
||||
applied: false,
|
||||
})
|
||||
|
@ -310,7 +310,7 @@ pub fn remove_unused_imports(
|
|||
Ok(Fix {
|
||||
content: state.to_string(),
|
||||
location: stmt.location,
|
||||
end_location: stmt.end_location,
|
||||
end_location: stmt.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ pub fn remove_unused_import_froms(
|
|||
Ok(Fix {
|
||||
content: state.to_string(),
|
||||
location: stmt.location,
|
||||
end_location: stmt.end_location,
|
||||
end_location: stmt.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1257,7 +1257,7 @@ where
|
|||
self.handle_node_store(
|
||||
&Expr::new(
|
||||
excepthandler.location,
|
||||
excepthandler.end_location,
|
||||
excepthandler.end_location.unwrap(),
|
||||
ExprKind::Name {
|
||||
id: name.to_string(),
|
||||
ctx: ExprContext::Store,
|
||||
|
@ -1271,7 +1271,7 @@ where
|
|||
self.handle_node_store(
|
||||
&Expr::new(
|
||||
excepthandler.location,
|
||||
excepthandler.end_location,
|
||||
excepthandler.end_location.unwrap(),
|
||||
ExprKind::Name {
|
||||
id: name.to_string(),
|
||||
ctx: ExprContext::Store,
|
||||
|
|
|
@ -317,9 +317,9 @@ pub fn blank_before_after_class(checker: &mut Checker, definition: &Definition)
|
|||
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
|
||||
check.amend(Fix::replacement(
|
||||
"\n".to_string(),
|
||||
Location::new(docstring.end_location.row() + 1, 1),
|
||||
Location::new(docstring.end_location.unwrap().row() + 1, 1),
|
||||
Location::new(
|
||||
docstring.end_location.row() + 1 + blank_lines_after,
|
||||
docstring.end_location.unwrap().row() + 1 + blank_lines_after,
|
||||
1,
|
||||
),
|
||||
));
|
||||
|
@ -482,8 +482,8 @@ pub fn newline_after_last_paragraph(checker: &mut Checker, definition: &Definiti
|
|||
check.amend(Fix::insertion(
|
||||
content,
|
||||
Location::new(
|
||||
docstring.end_location.row(),
|
||||
docstring.end_location.column() - "\"\"\"".len(),
|
||||
docstring.end_location.unwrap().row(),
|
||||
docstring.end_location.unwrap().column() - "\"\"\"".len(),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: &Optio
|
|||
check.amend(Fix {
|
||||
content,
|
||||
location: stmt.location,
|
||||
end_location: stmt.end_location,
|
||||
end_location: stmt.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use rustpython_ast::{Expr, ExprKind, Location};
|
||||
use rustpython_ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::autofix::fixer;
|
||||
|
@ -40,11 +40,8 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) {
|
|||
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
|
||||
check.amend(Fix {
|
||||
content: format!("self.{}", target),
|
||||
location: Location::new(expr.location.row(), expr.location.column()),
|
||||
end_location: Location::new(
|
||||
expr.end_location.row(),
|
||||
expr.end_location.column(),
|
||||
),
|
||||
location: expr.location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ pub fn duplicate_handler_exceptions(
|
|||
check.amend(Fix {
|
||||
content,
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args:
|
|||
check.amend(Fix {
|
||||
content: primitive.builtin(),
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn unnecessary_abspath(checker: &mut Checker, expr: &Expr, func: &Expr, args
|
|||
check.amend(Fix {
|
||||
content: "__file__".to_string(),
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr, id: &str) {
|
|||
check.amend(Fix {
|
||||
content: id.to_lowercase(),
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
check.amend(Fix {
|
||||
content,
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
check.amend(Fix {
|
||||
content,
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
})
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
check.amend(Fix {
|
||||
content,
|
||||
location: expr.location,
|
||||
end_location: expr.end_location,
|
||||
end_location: expr.end_location.unwrap(),
|
||||
applied: false,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ expression: checks
|
|||
row: 10
|
||||
column: 13
|
||||
fix:
|
||||
content: "raise AssertionError(\"message\")"
|
||||
content: "raise AssertionError('message')"
|
||||
location:
|
||||
row: 10
|
||||
column: 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue