Hacker News new | ask | show | jobs
by bratao 2737 days ago
Just to clarify. This behavior is expected since 3.6:

As of Python 3.6, for the CPython implementation of Python, dictionaries remember the order of items inserted. This is considered an implementation detail in Python 3.6; you need to use OrderedDict if you want insertion ordering that's guaranteed across other implementations of Python.

As of Python 3.7, this is no longer an implementation detail and instead becomes a language feature.

[1] https://stackoverflow.com/questions/39980323/are-dictionarie...

1 comments

CPython implementation detail vs. Python language feature remains a relatively meaningless distinction.
Even if you stick purely to CPython, it still matters in that there's no guarantee that it'll still be ordered when you update (if you were reading 3.6 dicts). It's not just an implementation detail for CPython, but an implementation detail for specifically CPython 3.6 (and any other version maintaining that status).

So now that its upgraded to language feature, you can actually expect backwards compatibility in future updates.

CPython is not the only Python interpreter out there.
The documentation sometimes suggests otherwise, but since there is no Python language specification, declaring something "part of the language" seems to have no meaning if it's not "implemented in CPython".

PyPy has had ordered dicts for longer than CPython, and Jython and IronPython don't look like they're ever going to support Python 3, so I'm not sure who this declaration is even even hypothetically relevant to.

It's relevant in the fact that you shouldn't rely on it as a programmer prior to this release. Changing it would have been considered a none breaking change.
Good point.
The other major python implementation, pypy, effectively implements CPython. (And insofar as it doens't, it's heading that way.)