Skip to content

Commit 0afb2d5

Browse files
committed
Simplified module API.
1 parent 3ea735c commit 0afb2d5

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub mod _inner {
2323

2424
#[pymodule_init]
2525
pub fn init(m: &Bound<'_, PyModule>) -> PyResult<()> {
26-
m.attach_submodule_with_sys(m.py(), pyo3::wrap_pymodule!(super::exceptions::py_err::pymod))?;
27-
m.attach_submodule_with_sys(m.py(), pyo3::wrap_pymodule!(super::js::pymod))?;
26+
m.attach_submodule_with_sys(pyo3::wrap_pymodule!(super::exceptions::py_err::pymod))?;
27+
m.attach_submodule_with_sys(pyo3::wrap_pymodule!(super::js::pymod))?;
2828
Ok(())
2929
}
3030
}

src/utils/py.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,22 @@ pub trait PyModuleExt<'py> {
3535
///
3636
/// #[pymodule_init]
3737
/// pub fn init(m: &Bound<'_, PyModule>) -> PyResult<()> {
38-
/// m.attach_submodule_with_sys(m.py(), pyo3::wrap_pymodule!(super::inner_mod))?;
38+
/// m.attach_submodule_with_sys(pyo3::wrap_pymodule!(super::inner_mod))?;
3939
/// }
4040
///}
4141
/// ```
4242
///
43-
fn attach_submodule_with_sys<ModFN>(
44-
&self,
45-
py: Python<'py>,
46-
wrapped_submod: ModFN,
47-
) -> pyo3::PyResult<()>
43+
fn attach_submodule_with_sys<ModFN>(&self, wrapped_submod: ModFN) -> pyo3::PyResult<()>
4844
where
4945
ModFN: Fn(Python<'py>) -> Py<PyModule>;
5046
}
5147

52-
impl<'py, T> PyModuleExt<'py> for T
53-
where
54-
T: PyModuleMethods<'py>,
55-
{
56-
fn attach_submodule_with_sys<ModFN>(
57-
&self,
58-
py: Python<'py>,
59-
wrapped_submod: ModFN,
60-
) -> pyo3::PyResult<()>
48+
impl<'py> PyModuleExt<'py> for pyo3::Bound<'py, PyModule> {
49+
fn attach_submodule_with_sys<ModFN>(&self, wrapped_submod: ModFN) -> pyo3::PyResult<()>
6150
where
6251
ModFN: Fn(Python<'py>) -> Py<PyModule>,
6352
{
53+
let py = self.py();
6454
let submod = wrapped_submod(py).into_bound(py);
6555
self.add_submodule(&submod)?;
6656
let sys_name = format!(

0 commit comments

Comments
 (0)