diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b8e662..a4964a87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] -## Fixed +### Added + + * Have `PyModule` generate an index of its members (`__all__` list). + +### Fixed * `type_object::PyTypeObject` has been marked unsafe because breaking the contract `type_object::PyTypeObject::init_type` can lead to UB. * Fixed automatic derive of `PySequenceProtocol` implementation in [#423](https://github.com/PyO3/pyo3/pull/423). diff --git a/src/types/module.rs b/src/types/module.rs index 047adbd2..10672cf6 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -83,7 +83,7 @@ impl PyModule { pub fn index(&self) -> PyResult<&PyList> { match self.getattr("__all__") { Ok(idx) => idx.downcast_ref().map_err(PyErr::from), - Err(err) => + Err(err) => { if err.is_instance::(self.py()) { let l = PyList::empty(self.py()); self.setattr("__all__", l).map_err(PyErr::from)?; @@ -91,6 +91,7 @@ impl PyModule { } else { Err(err) } + } } } @@ -158,7 +159,9 @@ impl PyModule { where V: ToPyObject, { - self.index()?.append(name).expect("could not append __name__ to __all__"); + self.index()? + .append(name) + .expect("could not append __name__ to __all__"); self.setattr(name, value) }