Skip to content

Commit

Permalink
fix declarative module compile error with create_exception! (#4086)
Browse files Browse the repository at this point in the history
* fix declarative module compile error with `create_exception!`

* add newsfragment
  • Loading branch information
Icxolu authored Apr 16, 2024
1 parent 2ad2a3f commit 03f59ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/4086.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes a compile error when exporting an exception created with `create_exception!` living in a different Rust module using the `declarative-module` feature.
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ macro_rules! pyobject_native_type_info(

impl $name {
#[doc(hidden)]
const _PYO3_DEF: $crate::impl_::pymodule::AddTypeToModule<Self> = $crate::impl_::pymodule::AddTypeToModule::new();
pub const _PYO3_DEF: $crate::impl_::pymodule::AddTypeToModule<Self> = $crate::impl_::pymodule::AddTypeToModule::new();
}
};
);
Expand Down
8 changes: 8 additions & 0 deletions tests/test_declarative_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ use pyo3::types::PyBool;
mod common;

mod some_module {
use pyo3::create_exception;
use pyo3::exceptions::PyException;
use pyo3::prelude::*;

#[pyclass]
pub struct SomePyClass;

create_exception!(some_module, SomeException, PyException);
}

#[pyclass]
Expand Down Expand Up @@ -61,6 +65,10 @@ mod declarative_module {
#[pymodule_export]
use super::some_module::SomePyClass;

// test for #4036
#[pymodule_export]
use super::some_module::SomeException;

#[pymodule]
mod inner {
use super::*;
Expand Down

0 comments on commit 03f59ea

Please sign in to comment.