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

Antoine Pitrou solipsis at pitrou.net
Wed Dec 20 04:24:04 EST 2017


On Tue, 19 Dec 2017 17:32:52 -0800
Nathaniel Smith <njs at pobox.com> wrote:
> 
> > In any case, there are so many ways
> > to spoil the first point for yourself that it's hardly worth treating as an
> > important constraint.  
> 
> I guess the underlying issue here is partly the question of what the
> pprint module is for. In my understanding, it's primarily a tool for
> debugging/introspecting Python programs, and the reason it talks about
> "valid input to the interpreter" isn't because we want anyone to
> actually feed the data back into the interpreter, [...]

Actually, when you want to include a large constant in a Python
program, pprint() can be useful to get a nicer formatting for your
source code.

That said, I do think that pprint() should continue sorting dicts by
default.  Even though dicts may be ordered *now*, most uses of dict
don't expect any particular order.

(I also think the pprint() example shows the potential confusion issues
with making dict ordered by default, as the user and implementor of an
API may not agree whether dict order is significant...)

Regards

Antoine.




More information about the Python-Dev mailing list