On 7/26/2018 1:23 PM, Terry Reedy wrote:
On 7/26/2018 1:21 PM, Terry Reedy wrote:
On python-idea,  Miro Hrončok asked today whether we can change the OrderedDict repr from, for instance,

OrderedDict([('a', '1'), ('b', '2')]) # to
OrderedDict({'a': '1', 'b': '2'})

I am not sure what our repr change policy is, as there is a back-compatibility issue but I remember there being changes.

Whoops, I meant to send this query elsewhere, so I could answer properly here.

I posted on pydev thread
[issue34221] Any plans to combine collections.OrderedDict with dict
and Raymond Hettinger, collections author and maintainer, replied:

We are allowed to change the repr in future versions of the language. Doing so does come at a cost though. There is a small performance penalty (see the timings below). Some doctests will break. And Python 3.8 printed output in books and blog posts would get shuffled if typed in to Python 3.5 -- this is problematic because one of the few remaining use cases for OrderedDict is to write code that is compatible with older Pythons.

The proposed repr does look pretty but probably isn't worth the disruption.

$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict([('a', '1'), ('b', '2')])"
200000 loops, best of 7: 1.12 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict({'a': '1', 'b': '2'})"
200000 loops, best of 7: 1.22 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict([('a', '1'), ('b', '2')])"
200000 loops, best of 7: 1.13 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict({'a': '1', 'b': '2'})"
200000 loops, best of 7: 1.2 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict([('a', '1'), ('b', '2')])"
200000 loops, best of 7: 1.12 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict({'a': '1', 'b': '2'})"
200000 loops, best of 7: 1.2 usec per loop

--
Terry Jan Reedy


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to