Skip to content

Commit

Permalink
fix declarative-modules compile error (#4054)
Browse files Browse the repository at this point in the history
* fix declarative-modules compile error

* add newsfragment
  • Loading branch information
Icxolu authored and davidhewitt committed Apr 16, 2024
1 parent fd18955 commit e501377
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/4054.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a compile error when exporting a `#[pyclass]` living in a different Rust module using the declarative-module feature.
2 changes: 1 addition & 1 deletion pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_declarative_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit e501377

Please # to comment.