Message282159
This issue was previously addressed and fixed here:
http://bugs.python.org/issue1351692
When subclassing PrettyPrinter, overriding the format() method should allow users to define custom pretty-printers.
However, for objects whose repr is short, format() is not called for the individual members.
Example code that reproduces the issue is as follows:
import pprint
import sys
pprint.pprint(sys.version_info)
class MyPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels, level):
if isinstance(object, int):
return hex(object), True, False
else:
return pprint.PrettyPrinter.format(self, object, context, maxlevels, level)
MyPrettyPrinter().pprint(10)
MyPrettyPrinter().pprint([10])
When run with different versions of Python:
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
0xa
[0xa]
(3, 0, 1, 'final', 0)
0xa
[10]
sys.version_info(major=3, minor=2, micro=5, releaselevel='final', serial=0)
0xa
[10]
sys.version_info(major=3, minor=4, micro=4, releaselevel='final', serial=0)
0xa
[10]
sys.version_info(major=3, minor=6, micro=0, releaselevel='beta', serial=4)
0xa
[10]
You'll notice that the regression exists in all versions >= 3.0,
even though the commit that fixed the issue is still in the log (2008-01-20):
https://hg.python.org/cpython/log/3.0/Lib/pprint.py
I have not had the time to look at the source of the issue or provide a fix; I might do so tonight. |
|
Date |
User |
Action |
Args |
2016-12-01 11:45:24 | mic_e | set | recipients:
+ mic_e, gvanrossum, doerwalter, anthonybaxter, georg.brandl, rhettinger, markhirota |
2016-12-01 11:45:23 | mic_e | set | messageid: <1480592723.97.0.369129599105.issue28850@psf.upfronthosting.co.za> |
2016-12-01 11:45:23 | mic_e | link | issue28850 messages |
2016-12-01 11:45:23 | mic_e | create | |
|