Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit 77d0d44

Browse files
committed
Include argument parentheses in range (#5)
1 parent f50d06a commit 77d0d44

6 files changed

+124
-110
lines changed

parser/src/function.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ mod tests {
136136
use super::*;
137137
use crate::{ast, parser::ParseErrorType, Parse};
138138

139-
#[cfg(feature = "all-nodes-with-ranges")]
140139
macro_rules! function_and_lambda {
141140
($($name:ident: $code:expr,)*) => {
142141
$(
@@ -149,6 +148,12 @@ mod tests {
149148
}
150149
}
151150

151+
#[cfg(feature = "all-nodes-with-ranges")]
152+
function_and_lambda! {
153+
test_function_no_args_with_ranges: "def f(): pass",
154+
test_function_pos_args_with_ranges: "def f(a, b, c): pass",
155+
}
156+
152157
#[cfg(feature = "all-nodes-with-ranges")]
153158
function_and_lambda! {
154159
test_function_no_args: "def f(): pass",

parser/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ...
11071107
@my_decorator
11081108
def test():
11091109
pass
1110-
1110+
11111111
@class_decorator
11121112
class Abcd:
11131113
pass

parser/src/python.lalrpop

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,14 @@ FuncDef: ast::Stmt = {
981981
Parameters: ast::Arguments = {
982982
<location:@L> "(" <a: (ParameterList<TypedParameter, StarTypedParameter, DoubleStarTypedParameter>)?> ")" <end_location:@R> =>? {
983983
a.as_ref().map(validate_arguments).transpose()?;
984+
985+
let range = optional_range(location, end_location);
984986
let args = a
985-
.unwrap_or_else(|| ast::Arguments::empty(optional_range(location, end_location)));
987+
.map(|mut arguments| {
988+
arguments.range = range;
989+
arguments
990+
})
991+
.unwrap_or_else(|| ast::Arguments::empty(range));
986992

987993
Ok(args)
988994
}

parser/src/python.rs

Lines changed: 13 additions & 107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_no_args_with_ranges.snap

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser/src/snapshots/rustpython_parser__function__tests__function_pos_args_with_ranges.snap

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)