Skip to content

Commit 9c862e5

Browse files
Icxoludavidhewitt
authored andcommitted
fix another unsafe_op_in_unsafe_fn trigger (#4753)
1 parent 5c681ca commit 9c862e5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pyo3-macros-backend/src/params.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ pub(crate) fn impl_regular_arg_param(
265265
)?
266266
}
267267
} else {
268+
let unwrap = quote! {unsafe { #pyo3_path::impl_::extract_argument::unwrap_required_argument(#arg_value) }};
268269
quote_arg_span! {
269270
#pyo3_path::impl_::extract_argument::from_py_with(
270-
#pyo3_path::impl_::extract_argument::unwrap_required_argument(#arg_value),
271+
#unwrap,
271272
#name_str,
272273
#from_py_with as fn(_) -> _,
273274
)?

tests/ui/forbid_unsafe.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ mod gh_4394 {
2828
pub struct Version;
2929
}
3030

31+
mod from_py_with {
32+
use pyo3::prelude::*;
33+
use pyo3::types::PyBytes;
34+
35+
fn bytes_from_py(bytes: &Bound<'_, PyAny>) -> PyResult<Vec<u8>> {
36+
Ok(bytes.downcast::<PyBytes>()?.as_bytes().to_vec())
37+
}
38+
39+
#[pyfunction]
40+
fn f(#[pyo3(from_py_with = "bytes_from_py")] _bytes: Vec<u8>) {}
41+
}
42+
3143
fn main() {}

0 commit comments

Comments
 (0)