Skip to content

Commit

Permalink
fix another unsafe_op_in_unsafe_fn trigger (#4753)
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu authored Dec 2, 2024
1 parent 2ed3bb4 commit 6ec499b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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() {}

0 comments on commit 6ec499b

Please sign in to comment.