Skip to content

Commit

Permalink
Merge pull request #1597 from m-ou-se/wrap-pyfunction-as-closure
Browse files Browse the repository at this point in the history
Expand wrap_pyfunction!() to a closure to improve deduction.
  • Loading branch information
davidhewitt committed May 6, 2021
2 parents dfee347 + d33c501 commit 4edc7c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub mod proc_macro {
#[macro_export]
macro_rules! wrap_pyfunction {
($function_name: ident) => {{
&pyo3::paste::expr! { [<__pyo3_get_function_ $function_name>] }
&|py| pyo3::paste::expr! { [<__pyo3_get_function_ $function_name>] }(py)
}};

($function_name: ident, $arg: expr) => {
Expand Down
13 changes: 13 additions & 0 deletions tests/test_wrap_pyfunction_deduction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use pyo3::{prelude::*, types::PyCFunction, wrap_pyfunction};

#[pyfunction]
fn f() {}

pub fn add_wrapped(wrapper: &impl Fn(Python) -> PyResult<&PyCFunction>) {
let _ = wrapper;
}

#[test]
fn wrap_pyfunction_deduction() {
add_wrapped(wrap_pyfunction!(f));
}

0 comments on commit 4edc7c6

Please sign in to comment.