py/modbuiltins: Keep class locals ordered as per their definition. by andrewleech · Pull Request #6130 · micropython/micropython
This is good, it allows to selectively create classes with ordered dicts for the locals. I would prefer to just merge that and not the commit that adds the
MICROPY_PY_CLASS_ORDERED_LOCALSoption, because doing it dynamically withtype()is then available to everyone without making a custom build.Would it work for your use-case to just use
type()?
No this only helps in a very small use case of ours. The class attribute ordering is required by structured_config module (https://gitlab.com/alelec/micropython-structured-config#field-documentation) which is somewhat similar the the new dataclasses in cpython (https://docs.python.org/3/library/dataclasses.html) where structures are defined as classes and the order of the attributes is important, along with the syntax of declaring them.
One of the primary features of structured_config is that auto-complete works as they appear as a normal class to editors, this would be lost if I tried to dynamically create them with type(), as well as the clear usage syntax.
The dynamic class ordering is needed for serialise/deserialise feature of structured_config where structures can be sent down the wire as json and re-created in the same order at the other end.