Title: pprint produces different output in 2.6 and 3.0
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: facundobatista Nosy List: alexandre.vassalotti, facundobatista, fdrake, humitos, terry.reedy
Priority: low Keywords: patch

Created on 2008-05-16 06:10 by alexandre.vassalotti, last changed 2008-06-21 17:44 by facundobatista. This issue is now closed.

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'],

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'],
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/ 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 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

(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!
Date User Action Args
2008-06-21 17:44:29facundobatistasetstatus: open -> closed
resolution: fixed
messages: + msg68524
2008-05-30 02:02:50facundobatistasetassignee: fdrake -> facundobatista
2008-05-29 11:15:51humitossetfiles: + pprint.rst.diff
messages: + msg67486
2008-05-29 05:38:57fdrakesetfiles: + test_pprint.diff
messages: + msg67473
2008-05-29 05:11:55fdrakesetmessages: + msg67471
versions: + Python 2.6, - Python 3.0
2008-05-29 05:01:52fdrakesetmessages: + msg67470
2008-05-29 04:59:26fdrakesetmessages: + msg67469
2008-05-26 02:03:08terry.reedysetassignee: fdrake
messages: + msg67360
nosy: + fdrake, terry.reedy
2008-05-24 15:14:03facundobatistasetnosy: + facundobatista
messages: + msg67303
versions: - Python 2.6
2008-05-24 02:05:25humitossetfiles: + pprint.diff
keywords: + patch
messages: + msg67280
nosy: + humitos
2008-05-16 06:10:53alexandre.vassalotticreate