Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyo3-macros-backend/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ pub(crate) fn impl_regular_arg_param(
)?
}
} else {
let unwrap = quote! {unsafe { #pyo3_path::impl_::extract_argument::unwrap_required_argument(#arg_value) }};
quote_arg_span! {
#pyo3_path::impl_::extract_argument::from_py_with(
#pyo3_path::impl_::extract_argument::unwrap_required_argument(#arg_value),
#unwrap,
#name_str,
#from_py_with as fn(_) -> _,
)?
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/forbid_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ mod gh_4394 {
pub struct Version;
}

mod from_py_with {
use pyo3::prelude::*;
use pyo3::types::PyBytes;

fn bytes_from_py(bytes: &Bound<'_, PyAny>) -> PyResult<Vec<u8>> {
Ok(bytes.downcast::<PyBytes>()?.as_bytes().to_vec())
}

#[pyfunction]
fn f(#[pyo3(from_py_with = "bytes_from_py")] _bytes: Vec<u8>) {}
}

fn main() {}
Loading