From 603a55f204e35b200a988168864e44ee7600310e Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:52:03 +0100 Subject: [PATCH] fix `#[pyclass]` could not be named `Probe` (#4794) --- newsfragments/4794.fixed.md | 1 + pyo3-macros-backend/src/pyclass.rs | 5 ++--- tests/test_compile_error.rs | 1 + tests/ui/pyclass_probe.rs | 6 ++++++ tests/ui/pyclass_send.stderr | 4 ++-- 5 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 newsfragments/4794.fixed.md create mode 100644 tests/ui/pyclass_probe.rs diff --git a/newsfragments/4794.fixed.md b/newsfragments/4794.fixed.md new file mode 100644 index 00000000000..9076234a5b3 --- /dev/null +++ b/newsfragments/4794.fixed.md @@ -0,0 +1 @@ +fix `#[pyclass]` could not be named `Probe` \ No newline at end of file diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 3ac3fa358db..914cd19c1a0 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -2294,10 +2294,9 @@ impl<'a> PyClassImplsBuilder<'a> { let assertions = if attr.options.unsendable.is_some() { TokenStream::new() } else { - let assert = quote_spanned! { cls.span() => assert_pyclass_sync::<#cls>(); }; + let assert = quote_spanned! { cls.span() => #pyo3_path::impl_::pyclass::assert_pyclass_sync::<#cls>(); }; quote! { const _: () = { - use #pyo3_path::impl_::pyclass::*; #assert }; } @@ -2337,7 +2336,7 @@ impl<'a> PyClassImplsBuilder<'a> { static DOC: #pyo3_path::sync::GILOnceCell<::std::borrow::Cow<'static, ::std::ffi::CStr>> = #pyo3_path::sync::GILOnceCell::new(); DOC.get_or_try_init(py, || { let collector = PyClassImplCollector::::new(); - build_pyclass_doc(<#cls as #pyo3_path::PyTypeInfo>::NAME, #doc, collector.new_text_signature()) + build_pyclass_doc(::NAME, #doc, collector.new_text_signature()) }).map(::std::ops::Deref::deref) } diff --git a/tests/test_compile_error.rs b/tests/test_compile_error.rs index b165c911735..05d9ccd6d2e 100644 --- a/tests/test_compile_error.rs +++ b/tests/test_compile_error.rs @@ -67,4 +67,5 @@ fn test_compile_errors() { #[cfg(all(not(Py_LIMITED_API), Py_3_11))] t.compile_fail("tests/ui/invalid_base_class.rs"); t.pass("tests/ui/ambiguous_associated_items.rs"); + t.pass("tests/ui/pyclass_probe.rs"); } diff --git a/tests/ui/pyclass_probe.rs b/tests/ui/pyclass_probe.rs new file mode 100644 index 00000000000..590af194f6f --- /dev/null +++ b/tests/ui/pyclass_probe.rs @@ -0,0 +1,6 @@ +use pyo3::prelude::*; + +#[pyclass] +pub struct Probe {} + +fn main() {} diff --git a/tests/ui/pyclass_send.stderr b/tests/ui/pyclass_send.stderr index 3ef9591f820..516df060b13 100644 --- a/tests/ui/pyclass_send.stderr +++ b/tests/ui/pyclass_send.stderr @@ -10,7 +10,7 @@ note: required because it appears within the type `NotSyncNotSend` | 5 | struct NotSyncNotSend(*mut c_void); | ^^^^^^^^^^^^^^ -note: required by a bound in `pyo3::impl_::pyclass::assertions::assert_pyclass_sync` +note: required by a bound in `assert_pyclass_sync` --> src/impl_/pyclass/assertions.rs | | pub const fn assert_pyclass_sync() @@ -52,7 +52,7 @@ note: required because it appears within the type `SendNotSync` | 8 | struct SendNotSync(*mut c_void); | ^^^^^^^^^^^ -note: required by a bound in `pyo3::impl_::pyclass::assertions::assert_pyclass_sync` +note: required by a bound in `assert_pyclass_sync` --> src/impl_/pyclass/assertions.rs | | pub const fn assert_pyclass_sync()