From 672e23abcdf4b36bb850f0f4b7a62ab7af4de46b Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 26 Mar 2024 07:33:02 -0400 Subject: [PATCH] Attempt to mark various generated code with `#[automatically_derived]` fixes #3989 --- pyo3-macros-backend/src/method.rs | 4 ++++ pyo3-macros-backend/src/pyclass.rs | 2 ++ src/exceptions.rs | 1 + 3 files changed, 7 insertions(+) diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index 1a46d333c3b..30adcbf8e1a 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -621,6 +621,7 @@ impl<'a> FnSpec<'a> { let init_holders = holders.init_holders(ctx); quote! { + #[automatically_derived] unsafe fn #ident<'py>( py: #pyo3_path::Python<'py>, _slf: *mut #pyo3_path::ffi::PyObject, @@ -642,6 +643,7 @@ impl<'a> FnSpec<'a> { let check_gil_refs = holders.check_gil_refs(); quote! { + #[automatically_derived] unsafe fn #ident<'py>( py: #pyo3_path::Python<'py>, _slf: *mut #pyo3_path::ffi::PyObject, @@ -667,6 +669,7 @@ impl<'a> FnSpec<'a> { let check_gil_refs = holders.check_gil_refs(); quote! { + #[automatically_derived] unsafe fn #ident<'py>( py: #pyo3_path::Python<'py>, _slf: *mut #pyo3_path::ffi::PyObject, @@ -693,6 +696,7 @@ impl<'a> FnSpec<'a> { let init_holders = holders.init_holders(ctx); let check_gil_refs = holders.check_gil_refs(); quote! { + #[automatically_derived] unsafe fn #ident( py: #pyo3_path::Python<'_>, _slf: *mut #pyo3_path::ffi::PyTypeObject, diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 5122d205640..a6d6e60b3ea 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -1301,10 +1301,12 @@ fn impl_pytypeinfo( quote! { #[allow(deprecated)] + #[automatically_derived] unsafe impl #pyo3_path::type_object::HasPyGilRef for #cls { type AsRefTarget = #pyo3_path::PyCell; } + #[automatically_derived] 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/src/exceptions.rs b/src/exceptions.rs index add958257ab..3f00cbbf8d7 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -103,6 +103,7 @@ macro_rules! import_exception { #module=::std::option::Option::Some(stringify!($module)) ); + #[automatically_derived] impl $name { fn type_object_raw(py: $crate::Python<'_>) -> *mut $crate::ffi::PyTypeObject { use $crate::sync::GILOnceCell;