> On Jul 26, 2018, at 10:23 AM, Terry Reedy <tjre...@udel.edu> 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.
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. Raymond ------------------ $ 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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com