Merge pull request #1597 from m-ou-se/wrap-pyfunction-as-closure

Expand wrap_pyfunction!() to a closure to improve deduction.
This commit is contained in:
David Hewitt 2021-05-06 22:57:55 +01:00 committed by GitHub
commit 4edc7c6dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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) => {

View File

@ -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));
}