Shorter pprint's for empty sets and frozensets. Fix indentation of frozensets. Add tests including two complex data structures.

This commit is contained in:
Raymond Hettinger 2008-01-24 21:47:56 +00:00
parent 6170874f9c
commit 5310b69419
2 changed files with 200 additions and 2 deletions

View file

@ -167,25 +167,31 @@ class PrettyPrinter:
(issubclass(typ, set) and r is set.__repr__) or
(issubclass(typ, frozenset) and r is frozenset.__repr__)
):
length = _len(object)
if issubclass(typ, list):
write('[')
endchar = ']'
elif issubclass(typ, set):
if not length:
write('set()')
return
write('set([')
endchar = '])'
object = sorted(object)
indent += 4
elif issubclass(typ, frozenset):
if not length:
write('frozenset()')
return
write('frozenset([')
endchar = '])'
object = sorted(object)
indent += 9
indent += 10
else:
write('(')
endchar = ')'
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
length = _len(object)
if length:
context[objid] = 1
indent = indent + self._indent_per_level