-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
Python 3.7 made dicts ordered by default, see https://docs.python.org/3/whatsnew/3.7.html
Since it's part of the Python spec, and there are situations where this feature is useful, it makes sense to consider how MicroPython could support it. It may be that it's not realistic to have such a feature in MicroPython by default, maybe in the end it's just a build option for those who need it.
The problem is that implementing it efficiently (retaining O(1) lookup) requires more memory for the dict implementation than is currently used. The alternative is to make lookups O(N) which is proposed in #5323 (see that PR for further discussion).
Another alternative might be to just have ordered dicts only in certain places. There are currently requests for it in the following places:
- class members / locals-dict: py/modbuiltins: Keep class locals ordered as per their definition. #6130
- json loading of dicts: extmod/modujson: Allow json.loads() to preserve dict order. #6135