fix declarative-modules compile error (#4054)

* fix declarative-modules compile error

* add newsfragment
This commit is contained in:
Icxolu 2024-04-12 08:34:27 +02:00 committed by GitHub
parent c8b59d7117
commit ee5216f406
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1 @@
Fixes a compile error when exporting a `#[pyclass]` living in a different Rust module using the declarative-module feature.

View file

@ -1614,7 +1614,7 @@ impl<'a> PyClassImplsBuilder<'a> {
quote! { quote! {
impl #cls { impl #cls {
#[doc(hidden)] #[doc(hidden)]
const _PYO3_DEF: #pyo3_path::impl_::pymodule::AddClassToModule<Self> = #pyo3_path::impl_::pymodule::AddClassToModule::new(); pub const _PYO3_DEF: #pyo3_path::impl_::pymodule::AddClassToModule<Self> = #pyo3_path::impl_::pymodule::AddClassToModule::new();
} }
} }
} }

View file

@ -9,6 +9,13 @@ use pyo3::types::PyBool;
#[path = "../src/tests/common.rs"] #[path = "../src/tests/common.rs"]
mod common; mod common;
mod some_module {
use pyo3::prelude::*;
#[pyclass]
pub struct SomePyClass;
}
#[pyclass] #[pyclass]
struct ValueClass { struct ValueClass {
value: usize, value: usize,
@ -50,6 +57,10 @@ mod declarative_module {
#[pymodule_export] #[pymodule_export]
use super::{declarative_module2, double, MyError, ValueClass as Value}; use super::{declarative_module2, double, MyError, ValueClass as Value};
// test for #4036
#[pymodule_export]
use super::some_module::SomePyClass;
#[pymodule] #[pymodule]
mod inner { mod inner {
use super::*; use super::*;