Skip to content

Commit 3b3b0e6

Browse files
committed
Merge pull request #220 from lausek/master
ignore trailing comma in plist parsing
2 parents 690ac16 + a75b07f commit 3b3b0e6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/argparse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ macro_rules! py_argparse_parse_plist_impl {
197197
// TT muncher macro that does the main work for py_argparse_parse_plist!.
198198

199199
// Base case: all parameters handled
200-
{ $callback:ident { $($initial_arg:tt)* } $output:tt ( ) } => {
200+
{ $callback:ident { $($initial_arg:tt)* } $output:tt ( $(,)? ) } => {
201201
$crate::$callback! { $($initial_arg)* $output }
202202
};
203203
// Kwargs parameter with reference extraction

tests/test_function.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ fn one_arg() {
8080
assert!(obj.call(py, NoArgs, Some(&dict)).is_err());
8181
}
8282

83+
#[test]
84+
fn trailing_comma() {
85+
fn f(_py: Python, i: usize, j: usize) -> PyResult<usize> {
86+
Ok(i + j)
87+
}
88+
89+
let gil = Python::acquire_gil();
90+
let py = gil.python();
91+
// Define a function where the parameters are on separate
92+
// lines with trailing commas.
93+
let obj = py_fn!(
94+
py,
95+
f(
96+
first_parameter_with_long_name: usize,
97+
second_parameter_with_long_name: usize,
98+
)
99+
);
100+
assert_eq!(
101+
obj.call(py, (1, 1), None)
102+
.unwrap()
103+
.extract::<i32>(py)
104+
.unwrap(),
105+
2
106+
);
107+
}
108+
83109
#[test]
84110
fn inline_two_args() {
85111
let gil = Python::acquire_gil();

0 commit comments

Comments
 (0)