[Python-Dev] Guarantee ordered dict literals in v3.7? (original) (raw)

Barry Warsaw barry at python.org
Tue Dec 19 21:56:13 EST 2017


On Dec 19, 2017, at 20:32, Nathaniel Smith <njs at pobox.com> wrote:

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, but to emphasize that it provides an accurate what-you-see-is-what's-really-there view into how the interpreter understands a given object. It also emphasizes that this is not intended for display to end users; making the output format be "Python code" suggests that the main intended audience is people who know how to read, well, Python code, and therefore can be expected to care about Python's semantics.

pprint.pprint() is indeed mostly for debugging, but not always. As an example of what will break if you change the sorting guarantee: in Mailman 3 the REST etag is calculated from the pprint.pformat() of the result dictionary before it’s JSON-ified. If the order is changed, then it’s possible a client will have an incorrect etag for a structure that is effectively the same.

-Barry

-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: <http://mail.python.org/pipermail/python-dev/attachments/20171219/675dd934/attachment.sig>



More information about the Python-Dev mailing list