Commit 270a9411 authored by Raymond Hettinger's avatar Raymond Hettinger

Let pprint() support sets and frozensets (suggested by David Mertz).

parent 4cb196cc
...@@ -25,6 +25,9 @@ width constraint. ...@@ -25,6 +25,9 @@ width constraint.
dictionary was sorted only if its display required more than one line, although dictionary was sorted only if its display required more than one line, although
that wasn't documented. that wasn't documented.
.. versionchanged:: 2.6
Added support for :class:`set` and :class:`frozenset`.
The :mod:`pprint` module defines one class: The :mod:`pprint` module defines one class:
.. First the implementation class: .. First the implementation class:
......
...@@ -162,11 +162,24 @@ class PrettyPrinter: ...@@ -162,11 +162,24 @@ class PrettyPrinter:
write('}') write('}')
return return
if (issubclass(typ, list) and r is list.__repr__) or \ if ((issubclass(typ, list) and r is list.__repr__) or
(issubclass(typ, tuple) and r is tuple.__repr__): (issubclass(typ, tuple) and r is tuple.__repr__) or
(issubclass(typ, set) and r is set.__repr__) or
(issubclass(typ, frozenset) and r is frozenset.__repr__)
):
if issubclass(typ, list): if issubclass(typ, list):
write('[') write('[')
endchar = ']' endchar = ']'
elif issubclass(typ, set):
write('set([')
endchar = '])'
object = sorted(object)
indent += 4
elif issubclass(typ, frozenset):
write('frozenset([')
endchar = '])'
object = sorted(object)
indent += 9
else: else:
write('(') write('(')
endchar = ')' endchar = ')'
......
...@@ -378,6 +378,8 @@ Core and builtins ...@@ -378,6 +378,8 @@ Core and builtins
Library Library
------- -------
- The pprint module now supports sets and frozensets.
- #1221598: add optional callbacks to ftplib.FTP's storbinary() and - #1221598: add optional callbacks to ftplib.FTP's storbinary() and
storlines() methods. (Contributed by Phil Schwartz) storlines() methods. (Contributed by Phil Schwartz)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment