diff --git a/Cargo.lock b/Cargo.lock index a2155e25a9..864f6afca5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index f543350db9..fa80e64deb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/ast/relocate.rs b/src/ast/relocate.rs index 0e64f87fb4..ccc69385aa 100644 --- a/src/ast/relocate.rs +++ b/src/ast/relocate.rs @@ -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 { diff --git a/src/ast/types.rs b/src/ast/types.rs index 7eaf901788..9e0e4d356b 100644 --- a/src/ast/types.rs +++ b/src/ast/types.rs @@ -18,7 +18,9 @@ impl Range { pub fn from_located(located: &Located) -> Self { Range { location: located.location, - end_location: located.end_location, + end_location: located + .end_location + .expect("AST nodes should have end_location."), } } } diff --git a/src/autofix/fixes.rs b/src/autofix/fixes.rs index 7a3dae8c0b..d04915ac7b 100644 --- a/src/autofix/fixes.rs +++ b/src/autofix/fixes.rs @@ -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, }) } diff --git a/src/check_ast.rs b/src/check_ast.rs index 6584473834..7bf848f8dd 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -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, diff --git a/src/docstrings/plugins.rs b/src/docstrings/plugins.rs index aaafadb1e1..36275d9c08 100644 --- a/src/docstrings/plugins.rs +++ b/src/docstrings/plugins.rs @@ -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(), ), )); } diff --git a/src/plugins/assert_false.rs b/src/plugins/assert_false.rs index c4393f36d9..1d57a2ceac 100644 --- a/src/plugins/assert_false.rs +++ b/src/plugins/assert_false.rs @@ -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, }) } diff --git a/src/plugins/deprecated_unittest_alias.rs b/src/plugins/deprecated_unittest_alias.rs index 28b4fb8a5f..88f4110c76 100644 --- a/src/plugins/deprecated_unittest_alias.rs +++ b/src/plugins/deprecated_unittest_alias.rs @@ -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, }); } diff --git a/src/plugins/duplicate_exceptions.rs b/src/plugins/duplicate_exceptions.rs index 497b507f70..f21efe8a8e 100644 --- a/src/plugins/duplicate_exceptions.rs +++ b/src/plugins/duplicate_exceptions.rs @@ -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, }) } diff --git a/src/plugins/type_of_primitive.rs b/src/plugins/type_of_primitive.rs index f3ea339787..e358d91364 100644 --- a/src/plugins/type_of_primitive.rs +++ b/src/plugins/type_of_primitive.rs @@ -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, }); } diff --git a/src/plugins/unnecessary_abspath.rs b/src/plugins/unnecessary_abspath.rs index 372f253b10..2256d2aabe 100644 --- a/src/plugins/unnecessary_abspath.rs +++ b/src/plugins/unnecessary_abspath.rs @@ -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, }); } diff --git a/src/plugins/use_pep585_annotation.rs b/src/plugins/use_pep585_annotation.rs index 685c840953..3ee4459ac3 100644 --- a/src/plugins/use_pep585_annotation.rs +++ b/src/plugins/use_pep585_annotation.rs @@ -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, }) } diff --git a/src/plugins/use_pep604_annotation.rs b/src/plugins/use_pep604_annotation.rs index 3c6b270d63..3a67652912 100644 --- a/src/plugins/use_pep604_annotation.rs +++ b/src/plugins/use_pep604_annotation.rs @@ -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, }); } diff --git a/src/snapshots/ruff__linter__tests__B011_B011.py.snap b/src/snapshots/ruff__linter__tests__B011_B011.py.snap index c2868e1432..ad8b6e18fd 100644 --- a/src/snapshots/ruff__linter__tests__B011_B011.py.snap +++ b/src/snapshots/ruff__linter__tests__B011_B011.py.snap @@ -26,7 +26,7 @@ expression: checks row: 10 column: 13 fix: - content: "raise AssertionError(\"message\")" + content: "raise AssertionError('message')" location: row: 10 column: 1