Issue 2888: pprint produces different output in 2.6 and 3.0 (original) (raw)

Created on 2008-05-16 06:10 by alexandre.vassalotti, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pprint.diff humitos,2008-05-24 02:05
test_pprint.diff fdrake,2008-05-29 05:38 test for nested indentations
pprint.rst.diff humitos,2008-05-29 11:15
Messages (10)
msg66919 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2008-05-16 06:10
The indent argument produces different output in Python 2.6 and 3.0: Python 3.0a5+ (py3k:63349:63350M, May 16 2008, 00:37:17) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] >>> stuff.insert(0, stuff[:]) >>> pprint.pprint(stuff, indent=4) [ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'], 'spam', 'eggs', 'lumberjack', 'knights', 'ni'] Python 2.6a3+ (trunk:63323, May 15 2008, 16:09:01) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pprint >>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni'] >>> stuff.insert(0, stuff[:]) >>> pprint.pprint(stuff, indent=4) [ [ 'spam', 'eggs', 'lumberjack', 'knights', 'ni'], 'spam', 'eggs', 'lumberjack', 'knights', 'ni']
msg67280 - (view) Author: Manuel Kaufmann (humitos) * Date: 2008-05-24 02:05
If the correct way is the first option, we can use this patch to solve that error. I attached diff file. I use Lib/test/test_pprint.py to ensure that's works.
msg67303 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-05-24 15:13
It's not a 2.6 bug, as it behaves exactly as the documentation states. In Py3 it *is* different the result than the documentation. However, it's not clear to me if this behaviour is changed deliberately or by mistake (personally, I prefer this new way of showing it, so the documentation should be fixed). What do you think?
msg67360 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-05-26 02:03
I think I *slightly* prefer the 'new' way. Was pprint.py changed between 2.6 and 3.0? Or is the change a side-effect of 3.0 changes? Or of 2to3 if that was used? (In glancing through it, I did not see anything that needed change) Fred, I am assigning to you simply because you are listed as original author and *might* immediately know the answers.
msg67469 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-05-29 04:59
The version seen in py3k is the intended formatting; I don't remember anything about a change, but given the time I've not had in following commit messages and discussions, I could easily have missed something. I'm strongly in favor of the output from the Python 3.0 version; the 2.6 version is silly, even if you're not already laughing at the indent parameter. (When I first wrote pprint, I was working with huge nested tuples, for which I found the indentation control useful. Haven't used it since, though I suspect that's the sort of thing that makes others try it out.)
msg67470 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-05-29 05:01
I will note that Python 2.5 matches Python 3.0 in this regard.
msg67471 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-05-29 05:11
The patch doesn't include a new test to cover this case. That needs to be written and applied to both trunk and py3k.
msg67473 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2008-05-29 05:38
The attached test_pprint.diff adds a test for this problem. This test passes for the py3k and release25-maint branches and fails for the trunk. Applying Manuel Kaufmann's pprint.diff patch to the trunk causes it to pass as well. I'll leave it for someone else to figure out the right svnmerge dance to keep the trunk and py3k properly in sync. The test should be applied to the py3k, release25-maint, and trunk branches, at any rate.
msg67486 - (view) Author: Manuel Kaufmann (humitos) * Date: 2008-05-29 11:15
Documentation fix.
msg68524 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-06-21 17:44
Commited in 64446, thank you all!
History
Date User Action Args
2022-04-11 14:56:34 admin set github: 47137
2008-06-21 17:44:29 facundobatista set status: open -> closedresolution: fixedmessages: +
2008-05-30 02:02:50 facundobatista set assignee: fdrake -> facundobatista
2008-05-29 11:15:51 humitos set files: + pprint.rst.diffmessages: +
2008-05-29 05:38:57 fdrake set files: + test_pprint.diffmessages: +
2008-05-29 05:11:55 fdrake set messages: + versions: + Python 2.6, - Python 3.0
2008-05-29 05:01:52 fdrake set messages: +
2008-05-29 04:59:26 fdrake set messages: +
2008-05-26 02:03:08 terry.reedy set assignee: fdrakemessages: + nosy: + fdrake, terry.reedy
2008-05-24 15:14:03 facundobatista set nosy: + facundobatistamessages: + versions: - Python 2.6
2008-05-24 02:05:25 humitos set files: + pprint.diffkeywords: + patchmessages: + nosy: + humitos
2008-05-16 06:10:53 alexandre.vassalotti create