mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #19137: The pprint module now correctly formats instances of set and
frozenset subclasses.
This commit is contained in:
commit
092bd388ce
3 changed files with 84 additions and 28 deletions
|
@ -203,24 +203,22 @@ class PrettyPrinter:
|
|||
if issubclass(typ, list):
|
||||
write('[')
|
||||
endchar = ']'
|
||||
elif issubclass(typ, set):
|
||||
if not length:
|
||||
write('set()')
|
||||
return
|
||||
write('{')
|
||||
endchar = '}'
|
||||
object = sorted(object, key=_safe_key)
|
||||
elif issubclass(typ, frozenset):
|
||||
if not length:
|
||||
write('frozenset()')
|
||||
return
|
||||
write('frozenset({')
|
||||
endchar = '})'
|
||||
object = sorted(object, key=_safe_key)
|
||||
indent += 10
|
||||
else:
|
||||
elif issubclass(typ, tuple):
|
||||
write('(')
|
||||
endchar = ')'
|
||||
else:
|
||||
if not length:
|
||||
write(rep)
|
||||
return
|
||||
if typ is set:
|
||||
write('{')
|
||||
endchar = '}'
|
||||
else:
|
||||
write(typ.__name__)
|
||||
write('({')
|
||||
endchar = '})'
|
||||
indent += len(typ.__name__) + 1
|
||||
object = sorted(object, key=_safe_key)
|
||||
if self._indent_per_level > 1:
|
||||
write((self._indent_per_level - 1) * ' ')
|
||||
if length:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue