This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Recommend using pprint for deterministic doctest
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: charlax, docs@python, pitrou, r.david.murray
Priority: normal Keywords: patch

Created on 2014-01-20 07:19 by charlax, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pprint_doctest.patch charlax, 2014-01-20 07:19 Patch to replace sorted items with pprint in doctest warning review
Messages (4)
msg208526 - (view) Author: Charles-Axel Dein (charlax) * Date: 2014-01-20 07:19
I just thought that using pprint.pprint was an elegant solution to the non-deterministic order of repr(dict) in doctest. See for instance http://bugs.python.org/issue3332

Contrary to sorted(foo().items()):

- It provides a nice output that is exactly like a dict.
- It supports any number of nested dicts.
- It can be used in other cases as well to make doctests elegant.
msg208546 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-20 15:52
I think suggesting pprint is a great idea.  It also has another advantage in 3.4: in many cases it should produce output that is line wrapped such that NORMALIZE_WHITESPACE isn't needed.

However, I'd make it as an *additional* suggestion.  Pedagogically, sort makes it clear that you *must* resolve the problem of the ordering of dict items...then you can suggest pprint as something that also sorts, and has some additional nice properties as well.
msg208598 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-01-21 01:07
That's a rather bad idea. pprint output isn't supposed to be identical accross versions; actually, it has recently changed in some cases.
msg208619 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-21 06:23
That's a very good point.  You'd think I'd have thought of it since I mentioned that it had changed in 3.4.  And it will most likely change more in future versions.
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64509
2014-01-21 06:23:30r.david.murraysetstatus: open -> closed
resolution: rejected
messages: + msg208619

stage: resolved
2014-01-21 01:07:29pitrousetnosy: + pitrou
messages: + msg208598
2014-01-20 15:52:53r.david.murraysetnosy: + r.david.murray
messages: + msg208546
2014-01-20 07:19:58charlaxcreate