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! {
impl #cls {
#[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"]
mod common;
mod some_module {
use pyo3::prelude::*;
#[pyclass]
pub struct SomePyClass;
}
#[pyclass]
struct ValueClass {
value: usize,
@ -50,6 +57,10 @@ mod declarative_module {
#[pymodule_export]
use super::{declarative_module2, double, MyError, ValueClass as Value};
// test for #4036
#[pymodule_export]
use super::some_module::SomePyClass;
#[pymodule]
mod inner {
use super::*;