[Python-Dev] Guarantee ordered dict literals in v3.7?

Nick Coghlan ncoghlan at gmail.com
Tue Nov 7 01:39:53 EST 2017

On 7 November 2017 at 09:23, Chris Barker <chris.barker at noaa.gov> wrote:
> in short -- we don't have a choice (unless we add an explicit randomization
> as some suggested -- but that just seems perverse...)

And this is the key point for me: "choosing not to choose" is
effectively the same as standardising the feature, as enough Python
code will come to rely on CPython's behaviour that most alternative
implementations will feel obliged to start behaving the same way
CPython does (with MicroPython being the potential exception due to
memory usage constraints always winning over algorithmic efficiency
concerns in that context).

We added ResourceWarning a while back to help discourage reliance on
CPython promptly calling __del__ methods when dropping the last
reference to an object.

An equivalent for this case would be for dict objects to randomize
iteration (ala Go), once again requiring folks to opt-in via
collections.OrderedDict to get guaranteed ordering (perhaps with a
"o{}" dict display as new syntactic sugar).

But unless someone actually writes a PEP and implementation for that
in the next 12 weeks (and Guido accepts it), then we'll have 2
releases and 3 years of CPython working a particular way increasing
the inertia against making such a change in 3.8 (and beyond that, I'd
say we'd be well and truly into de facto standardisation territory,
and the chances of ever introducing deliberate perturbation of dict
iteration order would drop to nil).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list