diff --git a/NEWS.rst b/NEWS.rst index 89089391a4..5f95465cff 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -15,6 +15,9 @@ Note that ADIOS2 does not support compression in BP3 files. pybind11 2.12.0 is now the minimally supported version for Python support. +The ``len(...)`` of many classes has been reworked for consistency and returns now the number of entries (iterations, record components, etc.). +Previously, this sporadically returned the number of attributes, which is better queried via ``len(.attributes)``. + 0.15.0 ------ diff --git a/include/openPMD/binding/python/Container.H b/include/openPMD/binding/python/Container.H index a07847e600..cb42c89c00 100644 --- a/include/openPMD/binding/python/Container.H +++ b/include/openPMD/binding/python/Container.H @@ -85,6 +85,12 @@ declare_container(py::handle scope, std::string const &name) // keep container alive while iterator exists py::keep_alive<0, 1>()); + // overwrite to avoid that the __len__ of Attributable is used + cl.def( + "__len__", + [](const Map &m) { return m.size(); }, + "Number of elements in the container to iterate."); + cl.def("__repr__", [name](Map const &m) { std::stringstream stream; stream << "