(original) (raw)
On Tue, Dec 19, 2017 at 8:14 AM, Barry Warsaw <barry@python.org> wrote:
Nathaniel Smith has pointed out that eval(pprint(a\_dict)) is supposed to return the same dict -- so documented behavior may already be broken.
On Dec 18, 2017, at 22:37, Nathaniel Smith <njs@pobox.com> wrote:
\> Wait, what? Why would changing pprint (so that it accurately reflects
\> dict's new underlying semantics!) be a breaking change? Are you
\> suggesting it shouldn't be changed in 3.7?
As others have pointed out, exactly because the current behavior is documented. And we all know that if it’s documented (and often even if it’s not, but that’s besides the point here) it will be relied upon.
(though I assume order is still ignored when comparing dicts, so: eval(pprint(a\_dict)) == a\_dict will still hold.
But practicality beats purity, and a number of folks have already posted use-cases where they rely on sorted order, so there you go.
-- So we can’t change the default behavior. But I have no problems conceptually with giving users options. The devil is in the details though, e.g. should we special case dictionary sorting only?
Should we use a sort \`key\` to mirror sorted() and list.sort()?
That would be a nice feature! If anything is done, I think we should allow a key function.
and maybe have key=None as "unsorted"
-CHB
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov