Skip to content

Commit 4edc7c6

Browse files
authored
Merge pull request #1597 from m-ou-se/wrap-pyfunction-as-closure
Expand wrap_pyfunction!() to a closure to improve deduction.
2 parents dfee347 + d33c501 commit 4edc7c6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub mod proc_macro {
221221
#[macro_export]
222222
macro_rules! wrap_pyfunction {
223223
($function_name: ident) => {{
224-
&pyo3::paste::expr! { [<__pyo3_get_function_ $function_name>] }
224+
&|py| pyo3::paste::expr! { [<__pyo3_get_function_ $function_name>] }(py)
225225
}};
226226

227227
($function_name: ident, $arg: expr) => {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use pyo3::{prelude::*, types::PyCFunction, wrap_pyfunction};
2+
3+
#[pyfunction]
4+
fn f() {}
5+
6+
pub fn add_wrapped(wrapper: &impl Fn(Python) -> PyResult<&PyCFunction>) {
7+
let _ = wrapper;
8+
}
9+
10+
#[test]
11+
fn wrap_pyfunction_deduction() {
12+
add_wrapped(wrap_pyfunction!(f));
13+
}

0 commit comments

Comments
 (0)