[Python-checkins] python/dist/src/Lib pprint.py,1.26,1.27
doerwalter at users.sourceforge.net
doerwalter at users.sourceforge.net
Wed Dec 3 15:15:30 EST 2003
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv12889/Lib
Modified Files:
pprint.py
Log Message:
Patch #750542: pprint now will pretty print subclasses of list, tuple
and dict too, as long as they don't overwrite __repr__().
Index: pprint.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pprint.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** pprint.py 7 Jun 2003 20:47:37 -0000 1.26
--- pprint.py 3 Dec 2003 20:15:28 -0000 1.27
***************
*** 91,97 ****
indent = int(indent)
width = int(width)
! assert indent >= 0
assert depth is None or depth > 0, "depth must be > 0"
! assert width
self._depth = depth
self._indent_per_level = indent
--- 91,97 ----
indent = int(indent)
width = int(width)
! assert indent >= 0, "indent must be >= 0"
assert depth is None or depth > 0, "depth must be > 0"
! assert width, "width must be != 0"
self._depth = depth
self._indent_per_level = indent
***************
*** 131,135 ****
if sepLines:
! if typ is dict:
write('{')
if self._indent_per_level > 1:
--- 131,136 ----
if sepLines:
! r = typ.__repr__
! if issubclass(typ, dict) and r is dict.__repr__:
write('{')
if self._indent_per_level > 1:
***************
*** 158,163 ****
return
! if typ is list or typ is tuple:
! if typ is list:
write('[')
endchar = ']'
--- 159,165 ----
return
! if (issubclass(typ, list) and r is list.__repr__) or \
! (issubclass(typ, tuple) and r is tuple.__repr__):
! if issubclass(typ, list):
write('[')
endchar = ']'
***************
*** 180,184 ****
indent = indent - self._indent_per_level
del context[objid]
! if typ is tuple and length == 1:
write(',')
write(endchar)
--- 182,186 ----
indent = indent - self._indent_per_level
del context[objid]
! if issubclass(typ, tuple) and length == 1:
write(',')
write(endchar)
***************
*** 227,231 ****
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
! if typ is dict:
if not object:
return "{}", True, False
--- 229,234 ----
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
! r = typ.__repr__
! if issubclass(typ, dict) and r is dict.__repr__:
if not object:
return "{}", True, False
***************
*** 252,257 ****
return "{%s}" % _commajoin(components), readable, recursive
! if typ is list or typ is tuple:
! if typ is list:
if not object:
return "[]", True, False
--- 255,261 ----
return "{%s}" % _commajoin(components), readable, recursive
! if (issubclass(typ, list) and r is list.__repr__) or \
! (issubclass(typ, tuple) and r is tuple.__repr__):
! if issubclass(typ, list):
if not object:
return "[]", True, False
More information about the Python-checkins
mailing list