Skip to content

Commit

Permalink
Merge pull request dgrunwald#220 from lausek/master
Browse files Browse the repository at this point in the history
ignore trailing comma in plist parsing
  • Loading branch information
markbt committed Apr 24, 2020
2 parents 690ac16 + a75b07f commit 3b3b0e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/argparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ macro_rules! py_argparse_parse_plist_impl {
// TT muncher macro that does the main work for py_argparse_parse_plist!.

// Base case: all parameters handled
{ $callback:ident { $($initial_arg:tt)* } $output:tt ( ) } => {
{ $callback:ident { $($initial_arg:tt)* } $output:tt ( $(,)? ) } => {
$crate::$callback! { $($initial_arg)* $output }
};
// Kwargs parameter with reference extraction
Expand Down
26 changes: 26 additions & 0 deletions tests/test_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ fn one_arg() {
assert!(obj.call(py, NoArgs, Some(&dict)).is_err());
}

#[test]
fn trailing_comma() {
fn f(_py: Python, i: usize, j: usize) -> PyResult<usize> {
Ok(i + j)
}

let gil = Python::acquire_gil();
let py = gil.python();
// Define a function where the parameters are on separate
// lines with trailing commas.
let obj = py_fn!(
py,
f(
first_parameter_with_long_name: usize,
second_parameter_with_long_name: usize,
)
);
assert_eq!(
obj.call(py, (1, 1), None)
.unwrap()
.extract::<i32>(py)
.unwrap(),
2
);
}

#[test]
fn inline_two_args() {
let gil = Python::acquire_gil();
Expand Down

0 comments on commit 3b3b0e6

Please sign in to comment.