fix declarative module compile error with `create_exception!` (#4086)

* fix declarative module compile error with `create_exception!`

* add newsfragment
This commit is contained in:
Icxolu 2024-04-16 22:12:18 +02:00 committed by GitHub
parent 2ad2a3f208
commit 03f59eaf45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -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.

View File

@ -252,7 +252,7 @@ macro_rules! pyobject_native_type_info(
impl $name { impl $name {
#[doc(hidden)] #[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();
} }
}; };
); );

View File

@ -10,10 +10,14 @@ use pyo3::types::PyBool;
mod common; mod common;
mod some_module { mod some_module {
use pyo3::create_exception;
use pyo3::exceptions::PyException;
use pyo3::prelude::*; use pyo3::prelude::*;
#[pyclass] #[pyclass]
pub struct SomePyClass; pub struct SomePyClass;
create_exception!(some_module, SomeException, PyException);
} }
#[pyclass] #[pyclass]
@ -61,6 +65,10 @@ mod declarative_module {
#[pymodule_export] #[pymodule_export]
use super::some_module::SomePyClass; use super::some_module::SomePyClass;
// test for #4036
#[pymodule_export]
use super::some_module::SomeException;
#[pymodule] #[pymodule]
mod inner { mod inner {
use super::*; use super::*;