Skip to content

Commit e501377

Browse files
Icxoludavidhewitt
authored andcommitted
fix declarative-modules compile error (#4054)
* fix declarative-modules compile error * add newsfragment
1 parent fd18955 commit e501377

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

newsfragments/4054.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes a compile error when exporting a `#[pyclass]` living in a different Rust module using the declarative-module feature.

pyo3-macros-backend/src/pyclass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ impl<'a> PyClassImplsBuilder<'a> {
16141614
quote! {
16151615
impl #cls {
16161616
#[doc(hidden)]
1617-
const _PYO3_DEF: #pyo3_path::impl_::pymodule::AddClassToModule<Self> = #pyo3_path::impl_::pymodule::AddClassToModule::new();
1617+
pub const _PYO3_DEF: #pyo3_path::impl_::pymodule::AddClassToModule<Self> = #pyo3_path::impl_::pymodule::AddClassToModule::new();
16181618
}
16191619
}
16201620
}

tests/test_declarative_module.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ use pyo3::types::PyBool;
99
#[path = "../src/tests/common.rs"]
1010
mod common;
1111

12+
mod some_module {
13+
use pyo3::prelude::*;
14+
15+
#[pyclass]
16+
pub struct SomePyClass;
17+
}
18+
1219
#[pyclass]
1320
struct ValueClass {
1421
value: usize,
@@ -50,6 +57,10 @@ mod declarative_module {
5057
#[pymodule_export]
5158
use super::{declarative_module2, double, MyError, ValueClass as Value};
5259

60+
// test for #4036
61+
#[pymodule_export]
62+
use super::some_module::SomePyClass;
63+
5364
#[pymodule]
5465
mod inner {
5566
use super::*;

0 commit comments

Comments
 (0)