Skip to content

Commit

Permalink
docstrings++
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Dec 3, 2023
1 parent 45d54ba commit e355bcf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ use pyo3::prelude::*;
fn pdoc_pyo3_sample_library(py: Python<'_>, m: &PyModule) -> PyResult<()> {

let submodule = PyModule::new(py, "submodule")?;
submodule.add_function(wrap_pyfunction!(func, submodule)?)?;
submodule.setattr("__doc__", "This is a barebone PyO3 submodule with a child module.")?;
m.add_submodule(submodule)?;

let subsubmodule = PyModule::new(py, "subsubmodule")?;
subsubmodule.setattr("__doc__", "This is a sub-submodule with a function member.")?;
subsubmodule.add_function(wrap_pyfunction!(func, subsubmodule)?)?;
submodule.add_submodule(subsubmodule)?;

let explicit_submodule = PyModule::new(py, "explicit_submodule")?;
explicit_submodule.add_function(wrap_pyfunction!(func, explicit_submodule)?)?;
explicit_submodule.setattr("__doc__", "This is a submodule that has been explicitly registered in sys.modules.")?;
m.add_submodule(explicit_submodule)?;
py.import("sys")?
.getattr("modules")?
.set_item("pdoc_pyo3_sample_library.explicit_submodule", explicit_submodule)?;

let correct_name_submodule = PyModule::new(py, "correct_name_submodule")?;
correct_name_submodule.add_function(wrap_pyfunction!(func, correct_name_submodule)?)?;
correct_name_submodule.setattr("__doc__", "This is a submodule with a patched __name__ to include the parent module name.")?;
m.add_submodule(correct_name_submodule)?;
// Needs to happen after .add_submodule()
correct_name_submodule.setattr("__name__", "pdoc_pyo3_sample_library.correct_name_submodule")?;

Ok(())
Expand Down

0 comments on commit e355bcf

Please sign in to comment.