diff --git a/src/argparse.rs b/src/argparse.rs index e4ca0edb..f5c50211 100644 --- a/src/argparse.rs +++ b/src/argparse.rs @@ -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 diff --git a/tests/test_function.rs b/tests/test_function.rs index ab39b6e3..35df0a88 100644 --- a/tests/test_function.rs +++ b/tests/test_function.rs @@ -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 { + 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::(py) + .unwrap(), + 2 + ); +} + #[test] fn inline_two_args() { let gil = Python::acquire_gil();