[Python-Dev] Guarantee ordered dict literals in v3.7?
Steven D'Aprano
steve at pearwood.info
Mon Dec 18 22:58:18 EST 2017
On Mon, Dec 18, 2017 at 07:37:03PM -0800, Nathaniel Smith wrote:
> On Mon, Dec 18, 2017 at 7:02 PM, Barry Warsaw <barry at python.org> wrote:
> > On Dec 18, 2017, at 21:11, Chris Barker <chris.barker at noaa.gov> wrote:
> >
> >> Will changing pprint be considered a breaking change?
> >
> > Yes, definitely.
>
> Wait, what? Why would changing pprint (so that it accurately reflects
> dict's new underlying semantics!) be a breaking change?
I have a script which today prints data like so:
{'Aaron': 62,
'Anne': 51,
'Bob': 23,
'George': 30,
'Karen': 45,
'Sue': 17,
'Sylvester': 34}
Tomorrow, it will suddenly start printing:
{'Bob': 23,
'Karen': 45,
'Sue': 17,
'George': 30,
'Aaron': 62,
'Anne': 51,
'Sylvester': 34}
and my users will yell at me that my script is broken because the data
is now in random order. Now, maybe that's my own damn fault for using
pprint instead of writing my own pretty printer... but surely the point
of pprint is so I don't have to write my own?
Besides, the docs say very prominently:
"Dictionaries are sorted by key before the display is computed."
https://docs.python.org/3/library/pprint.html
so I think I can be excused having relied on that feature.
--
Steve
More information about the Python-Dev
mailing list