diff --git a/guide/src/conversions/traits.md b/guide/src/conversions/traits.md index 4de449e365b..63fa81d2e70 100644 --- a/guide/src/conversions/traits.md +++ b/guide/src/conversions/traits.md @@ -442,6 +442,10 @@ If the input is neither a string nor an integer, the error message will be: - `pyo3(item)`, `pyo3(item("key"))` - retrieve the field from a mapping, possibly with the custom key specified as an argument. - can be any literal that implements `ToBorrowedObject` +- `pyo3(from_py_with = "...")` + - apply a custom function to convert the field from Python the desired Rust type. + - the argument must be the name of the function as a string. + - the function signature must be `fn(&PyAny) -> PyResult` where `T` is the Rust type of the argument. ### `IntoPy` diff --git a/tests/test_frompyobject.rs b/tests/test_frompyobject.rs index 29555d3f82e..41557f36312 100644 --- a/tests/test_frompyobject.rs +++ b/tests/test_frompyobject.rs @@ -483,10 +483,7 @@ fn test_from_py_with() { } #[derive(Debug, FromPyObject)] -pub struct ZapTuple( - String, - #[pyo3(from_py_with = "PyAny::len")] usize, -); +pub struct ZapTuple(String, #[pyo3(from_py_with = "PyAny::len")] usize); #[test] fn test_from_py_with_tuple_struct() {