[Patches] [ python-Patches-1373762 ] Tweak pprint.PrettyPrinter.format for subclassing
SourceForge.net
noreply at sourceforge.net
Mon Dec 5 21:48:45 CET 2005
Patches item #1373762, was opened at 2005-12-05 14:21
Message generated for change (Comment added) made by fdrake
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1373762&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Mark Hirota (markhirota)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Tweak pprint.PrettyPrinter.format for subclassing
Initial Comment:
The current format() method doesn't recursively apply
an overridden format() method when the width of the
object is too short.
This patch is designed to remove that limitation and
allow a pprint.PrettyPrinter sublcass that could, for
example, print all ints and longs in hex:
class MyPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels,
level):
if isinstance(object, int):
return hex(object), True, False
else:
return pprintmod.PrettyPrinter.format(
self, object, context, maxlevels,
level)
>>> mpp = MyPrettyPrinter()
>>> mpp.pprint(range(10))
[0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9]
>>> mpp.pprint(range(0x10000000,0x10000010))
[0x10000000,
0x10000001,
0x10000002,
0x10000003,
0x10000004,
0x10000005,
0x10000006,
0x10000007,
0x10000008,
0x10000009,
0x1000000a,
0x1000000b,
0x1000000c,
0x1000000d,
0x1000000e,
0x1000000f]
The attached file contains "svn diff --diff-cmd diff -
x -b Lib/pprint.py".
----------------------------------------------------------------------
>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2005-12-05 15:48
Message:
Logged In: YES
user_id=3066
Heh, reading the diff alone doesn't help me; there's no
helpful context.
While the example use case doesn't seem interesting, I
consider non-support of sub-class overriding the format()
method to be a bug.
I'll try and look at the patch more seriously soon, but I've
not managed to eek out many tuits lately, and this week is
as massively overbooked as any these days.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2005-12-05 14:42
Message:
Logged In: YES
user_id=80475
I don't find the use case to be even slightly motivating.
Fred, what do you think of the patch?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1373762&group_id=5470
More information about the Patches
mailing list