diff --git a/CHANGELOG.md b/CHANGELOG.md index ecf442b5..e79d33df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Usage of `PyObject` with `#[pyo3(get)]`. [#760](https://github.com/PyO3/pyo3/pull/760) * `#[pymethods]` used in conjunction with `#[cfg]`. #[769](https://github.com/PyO3/pyo3/pull/769) * `"*"` in a `#[pyfunction()]` argument list incorrectly accepting any number of positional arguments (use `args = "*"` when this behaviour is desired). #[792](https://github.com/PyO3/pyo3/pull/792) +* `PyModule::dict` #[809](https://github.com/PyO3/pyo3/pull/809) ### Removed diff --git a/src/types/module.rs b/src/types/module.rs index 5f27ea03..f4e2dc36 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -72,7 +72,7 @@ impl PyModule { pub fn dict(&self) -> &PyDict { unsafe { self.py() - .from_owned_ptr::(ffi::PyModule_GetDict(self.as_ptr())) + .from_borrowed_ptr::(ffi::PyModule_GetDict(self.as_ptr())) } } diff --git a/tests/test_module.rs b/tests/test_module.rs index 535a74c9..6539bdf9 100644 --- a/tests/test_module.rs +++ b/tests/test_module.rs @@ -179,25 +179,34 @@ fn custom_named_fn() -> usize { } #[pymodule] -fn foobar_module(_py: Python, module: &PyModule) -> PyResult<()> { +fn foobar_module(_py: Python, m: &PyModule) -> PyResult<()> { use pyo3::wrap_pyfunction; - module.add_wrapped(wrap_pyfunction!(custom_named_fn)) + m.add_wrapped(wrap_pyfunction!(custom_named_fn))?; + m.dict().set_item("yay", "me")?; + Ok(()) } #[test] fn test_custom_names() { - use pyo3::wrap_pymodule; - let gil = Python::acquire_gil(); let py = gil.python(); - let module = wrap_pymodule!(foobar_module)(py); + let module = pyo3::wrap_pymodule!(foobar_module)(py); py_assert!(py, module, "not hasattr(module, 'custom_named_fn')"); py_assert!(py, module, "module.foobar() == 42"); } +#[test] +fn test_module_dict() { + let gil = Python::acquire_gil(); + let py = gil.python(); + let module = pyo3::wrap_pymodule!(foobar_module)(py); + + py_assert!(py, module, "module.yay == 'me'"); +} + #[pyfunction] fn subfunction() -> String { "Subfunction".to_string()