Skip to content

Commit

Permalink
Back to hardcoding the method name.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMazare committed Oct 6, 2021
1 parent 6c71b7a commit 1723218
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/types/function.rs
Original file line number Diff line number Diff line change
@@ -80,11 +80,7 @@ impl PyCFunction {
}

/// Create a new function from a closure.
pub fn new_closure<'a, F, R>(
function_name: &'static str,
f: F,
py: Python<'a>,
) -> PyResult<&'a PyCFunction>
pub fn new_closure<F, R>(f: F, py: Python) -> PyResult<&PyCFunction>
where
F: Fn(&types::PyTuple, Option<&types::PyDict>) -> PyResult<R> + Send + 'static,
R: crate::callback::IntoPyCallbackOutput<*mut ffi::PyObject>,
@@ -98,7 +94,7 @@ impl PyCFunction {
)
};
let method_def = methods::PyMethodDef::cfunction_with_keywords(
function_name,
"pyo3-closure",
methods::PyCFunctionWithKeywords(run_closure::<F, R>),
"",
);
4 changes: 2 additions & 2 deletions tests/test_pyfunction.rs
Original file line number Diff line number Diff line change
@@ -239,7 +239,7 @@ fn test_closure() {
.collect();
Ok(res)
};
let closure_py = PyCFunction::new_closure("closure", f, py).unwrap();
let closure_py = PyCFunction::new_closure(f, py).unwrap();

py_assert!(py, closure_py, "closure_py(42) == [43]");
py_assert!(
@@ -260,7 +260,7 @@ fn test_closure_counter() {
*counter += 1;
Ok(*counter)
};
let counter_py = PyCFunction::new_closure("counter", counter_fn, py).unwrap();
let counter_py = PyCFunction::new_closure(counter_fn, py).unwrap();

py_assert!(py, counter_py, "counter_py() == 1");
py_assert!(py, counter_py, "counter_py() == 2");

0 comments on commit 1723218

Please sign in to comment.