mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Shorter pprint's for empty sets and frozensets. Fix indentation of frozensets. Add tests including two complex data structures.
This commit is contained in:
parent
6170874f9c
commit
5310b69419
2 changed files with 200 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue