diff --git a/newsfragments/4308.changed.md b/newsfragments/4308.changed.md new file mode 100644 index 00000000000..6b5310cdd36 --- /dev/null +++ b/newsfragments/4308.changed.md @@ -0,0 +1 @@ +Nested declarative `#[pymodule]` are automatically treated as submodules (no `PyInit_` entrypoint is created) diff --git a/pyo3-macros-backend/src/module.rs b/pyo3-macros-backend/src/module.rs index faa7032de80..810028c3fd7 100644 --- a/pyo3-macros-backend/src/module.rs +++ b/pyo3-macros-backend/src/module.rs @@ -237,6 +237,7 @@ pub fn pymodule_module_impl( )? { set_module_attribute(&mut item_mod.attrs, &full_name); } + item_mod.attrs.push(parse_quote!(#[pyo3(submodule)])); } } Item::ForeignMod(item) => { diff --git a/tests/test_declarative_module.rs b/tests/test_declarative_module.rs index 0bf426a52cc..93ab40f7309 100644 --- a/tests/test_declarative_module.rs +++ b/tests/test_declarative_module.rs @@ -115,7 +115,7 @@ mod declarative_module { } } - #[pymodule(submodule)] + #[pymodule] #[pyo3(module = "custom_root")] mod inner_custom_root { use super::*;