From 4a6d0bf8f0c7f4e7308fd22d71a6cd32e6dc1d62 Mon Sep 17 00:00:00 2001 From: Lily Foote Date: Tue, 30 Jul 2024 19:57:30 +0100 Subject: [PATCH] Add missing #[allow(unsafe_code)] attributes Fixes #4394. --- newsfragments/4396.fixed.md | 1 + pyo3-macros-backend/src/pyclass.rs | 1 + pyo3-macros-backend/src/pymethod.rs | 2 ++ 3 files changed, 4 insertions(+) create mode 100644 newsfragments/4396.fixed.md diff --git a/newsfragments/4396.fixed.md b/newsfragments/4396.fixed.md new file mode 100644 index 00000000000..285358ad526 --- /dev/null +++ b/newsfragments/4396.fixed.md @@ -0,0 +1 @@ +Hide confusing warnings about unsafe usage in `#[pyclass]` implementation. diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 6fba5b7e23e..2936f05cd44 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1744,6 +1744,7 @@ fn impl_pytypeinfo(cls: &syn::Ident, attr: &PyClassArgs, ctx: &Ctx) -> TokenStre }; quote! { + #[allow(unsafe_code)] unsafe impl #pyo3_path::type_object::PyTypeInfo for #cls { const NAME: &'static str = #cls_name; const MODULE: ::std::option::Option<&'static str> = #module; diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index 77cc9ed5cc6..584dd8f04dd 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -772,6 +772,7 @@ pub fn impl_py_getter_def( use #pyo3_path::impl_::pyclass::Probe; struct Offset; + #[allow(unsafe_code)] unsafe impl #pyo3_path::impl_::pyclass::OffsetCalculator<#cls, #ty> for Offset { fn offset() -> usize { #pyo3_path::impl_::pyclass::class_offset::<#cls>() + @@ -779,6 +780,7 @@ pub fn impl_py_getter_def( } } + #[allow(unsafe_code)] const GENERATOR: #pyo3_path::impl_::pyclass::PyClassGetterGenerator::< #cls, #ty,