[Python-ideas] Change repr of collections.OrderedDict to be more dict-like

David Mertz mertz at gnosis.cx
Thu Jul 26 13:28:12 EDT 2018


Repr changes are likely to break doctests, at least. That's not necessarily
an absolute "no", but it does raise the bar.

On Thu, Jul 26, 2018, 1:22 PM Terry Reedy <tjreedy at udel.edu> wrote:

> On 7/26/2018 4:12 AM, Miro Hrončok wrote:
> > Hi,
> >
> > now when dicts are sorted, can we change the repr of
> > collections.OrderedDict to look like dict?
> >
> > I mean from:
> >
> >      OrderedDict([('a', '1'), ('b', '2')])
> >
> > To:
> >
> >      OrderedDict({'a': '1', 'b': '2'})
> >
> > I assume the current list-of-tuples repr is there so copy pasting the
> > repr to the interpreter results in the same OrderedDict. When dicts
> > preserve insertion order, this now works with dict.
> >
> > I consider the dict-based repr much easier to read.
> >
> > Thoughts?
>
> 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.
>
> --
> Terry Jan Reedy
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180726/2b6b4ff5/attachment.html>


More information about the Python-ideas mailing list