Skip to content

Commit

Permalink
fix(python): in check_replacements() handle both single line and mu…
Browse files Browse the repository at this point in the history
…lti line hanging comma after removing kwargs

fixes getgrit#416
  • Loading branch information
Alex-ley-scrub committed Oct 26, 2024
1 parent d8158ba commit bc3595f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12324,7 +12324,7 @@ fn trailing_comma_after_argument_removal_one_line() {
"#
.to_owned(),
expected: r#"
TaskMetadata(description="Parallel news titles from the Tbilisi City Hall website (https://tbilisi.gov.ge/).", main_score="f1", domains=["News"], text_creation="created", reference="https://huggingface.co/datasets/jupyterjazz/tbilisi-city-hall-titles")
TaskMetadata(description="Parallel news titles from the Tbilisi City Hall website (https://tbilisi.gov.ge/).", main_score="f1", domains=["News"], text_creation="created", reference="https://huggingface.co/datasets/jupyterjazz/tbilisi-city-hall-titles")
"#
.to_owned(),
}
Expand Down
10 changes: 10 additions & 0 deletions crates/language/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ impl Language for Python {
}

fn check_replacements(&self, n: NodeWithSource<'_>, replacements: &mut Vec<Replacement>) {
// https://github.com/getgrit/gritql/issues/416 multi line example
if n.node.kind() == "," {
if let Some(prev) = n.node.prev_sibling() {
let empty = prev.range().end_byte() == prev.range().start_byte();
if prev.kind() == "identifier" && empty {
replacements.push(Replacement::new(n.range(), ""));
}
}
}
if n.node.is_error() {
// https://github.com/getgrit/gritql/issues/416 single line example
if n.text().is_ok_and(|t| t == "->") || n.text().is_ok_and(|t| t == ",") {
replacements.push(Replacement::new(n.range(), ""));
}
Expand Down

0 comments on commit bc3595f

Please sign in to comment.