[Python-Dev] Guarantee ordered dict literals in v3.7? (original) (raw)

Paul Moore p.f.moore at gmail.com
Tue Nov 7 04:59:06 EST 2017


On 7 November 2017 at 06:39, Nick Coghlan <ncoghlan at gmail.com> wrote:

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).

Personally, I think that having an ordered implementation and then deliberately breaking that ordering is pretty silly. Not least because we chose not to do that for 3.6. So we're left with the simple question of whether we make the behaviour required in the documentation (which is basically where this thread started). I see 3 options. First, we maintain the status quo, treat it as a CPython/PyPy implementation detail, and accept that this means that people will expect it - resulting in pressure on alternative implementations to conform, but without a language spec to support them. Second, we document the requirement in the language spec, requiring alternative implementations to either implement it or document it as a way in which they don't confirm to the language spec (which is unattractive for them, as "implements the official Python language spec" is a selling point). Or third, we could document it as an optional behaviour, that language implementations are expected to implement if possible, and if they can't they should document the variance. That is to some extent the best of both worlds, in that it allows implementations to claim conformance with the spec while still not implementing the feature if it causes them problems to do so - they just have to document that they don't implement this optional but recommended behaviour. The downside of this option is that there's no precedent for it in the Python spec (it's basically C's "implementation defined behaviour", which is something Python hasn't needed this far).

Paul



More information about the Python-Dev mailing list