From 74619143b61273212054181289bbfcc8cfb8f90e Mon Sep 17 00:00:00 2001 From: Thomas Tanon Date: Thu, 6 Jun 2024 23:19:37 +0200 Subject: [PATCH] Declarative modules: make sure to emit doc comments and other attributes (#4236) * Declarative modules: make sure to emmit doc comments and other attributes * Adds a test * Apply suggestions from code review --------- Co-authored-by: David Hewitt --- newsfragments/4236.fixed.md | 1 + pyo3-macros-backend/src/module.rs | 1 + tests/ui/pymodule_missing_docs.rs | 5 +++++ 3 files changed, 7 insertions(+) create mode 100644 newsfragments/4236.fixed.md diff --git a/newsfragments/4236.fixed.md b/newsfragments/4236.fixed.md new file mode 100644 index 00000000..f87d1694 --- /dev/null +++ b/newsfragments/4236.fixed.md @@ -0,0 +1 @@ +Declarative modules: do not discard doc comments on the `mod` node. \ No newline at end of file diff --git a/pyo3-macros-backend/src/module.rs b/pyo3-macros-backend/src/module.rs index 71d776bf..c1e46276 100644 --- a/pyo3-macros-backend/src/module.rs +++ b/pyo3-macros-backend/src/module.rs @@ -287,6 +287,7 @@ pub fn pymodule_module_impl(mut module: syn::ItemMod) -> Result { let initialization = module_initialization(&name, ctx); Ok(quote!( + #(#attrs)* #vis mod #ident { #(#items)* diff --git a/tests/ui/pymodule_missing_docs.rs b/tests/ui/pymodule_missing_docs.rs index 1b196fa6..ed7d772f 100644 --- a/tests/ui/pymodule_missing_docs.rs +++ b/tests/ui/pymodule_missing_docs.rs @@ -9,4 +9,9 @@ pub fn python_module(_m: &Bound<'_, PyModule>) -> PyResult<()> { Ok(()) } +#[cfg(feature = "experimental-declarative-modules")] +/// Some module documentation +#[pymodule] +pub mod declarative_python_module {} + fn main() {}