Issue 20310: Recommend using pprint for deterministic doctest (original) (raw)

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:57 admin set github: 64509
2014-01-21 06:23:30 r.david.murray set status: open -> closedresolution: rejectedmessages: + stage: resolved
2014-01-21 01:07:29 pitrou set nosy: + pitroumessages: +
2014-01-20 15:52:53 r.david.murray set nosy: + r.david.murraymessages: +
2014-01-20 07:19:58 charlax create