Re:Lesser known parts of Python standard library – Trickster...
by rbanffy on Thursday September 05, 2024 @12:00AM
(#41453349)
Also, dicts can become unordered at any time in the future. Right now the OrderedDict implementation is a thin layer over dict, but there are no guarantees it’ll always be that.
[ Parent
| on HN ]
Re:Lesser known parts of Python standard library – Trickster...
by wodenokoto on Thursday September 05, 2024 @12:09AM
(#41453386)
They can, but ordered dict can also become unordered in the future, should the steering committee decide.
But seriously: It’s no longer an implementation detail that dictionaries are ordered in Python. It’s a specification of how Python works.
Re:Lesser known parts of Python standard library – Trickster...
by rbanffy on Thursday September 05, 2024 @01:18PM
(#41458639)
I missed that in the 3.7 release notes.
Re:Lesser known parts of Python standard library – Trickster...
by judicious on Thursday September 05, 2024 @12:10AM
(#41453390)
There in lies another reason why OrderedDicts are still useful even in 3.12
Re:Lesser known parts of Python standard library – Trickster...
by rbanffy on Thursday September 05, 2024 @01:19PM
(#41458649)
Not really. It was pointed out that since 3.7 the order preserving behaviour is part of the spec for dicts.
Re:Lesser known parts of Python standard library – Trickster...
by judicious on Thursday September 05, 2024 @02:24PM
(#41459200)
I guess for most purposes, OrderedDicts are then obsolete, but I believe there are some extra convenience methods that they have, but I've only really needed to preserve order.
Makes you think what other parts of Python have become obsolete.
Re:Lesser known parts of Python standard library – Trickster...
by 3eb7988a1663 on Thursday September 05, 2024 @12:25AM
(#41453451)
Not true as of 3.7[0]
the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec.
[0] https://docs.python.org/3.7/whatsnew/3.7.html
Re:Lesser known parts of Python standard library – Trickster...
by rbanffy on Thursday September 05, 2024 @01:17PM
(#41458634)
Oh well... This is what I get to not look at release notes with lawyer eyes. Thanks for the correction.
Re:Lesser known parts of Python standard library – Trickster...
by SuchAnonMuchWow on Thursday September 05, 2024 @04:22AM
(#41454660)
dict are ordered to keep argument order when using named arguments in function calling. So it would be a non-trivial breaking change to revert this now.
I would argue that OrderedDict have more chances to be depreciated than dict becoming unordered again, since there is now little value to keep OrderedDict around now (and the methods currently specific to UnorderedDict could be added to dict).