diff --git a/NEWS.rst b/NEWS.rst index eaff473149..9a6274dcb5 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -16,6 +16,9 @@ Note that ADIOS2 does not support compression in BP3 files. CMake 3.22.0 is now the minimally supported version for CMake. 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 << "