diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-23 00:04:40 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-23 00:04:40 (GMT) |
commit | c226c311392abbda437300eaa9841d9e839854c0 (patch) | |
tree | ccb398c254698142f25f194ec561375dda85181f /Lib/pprint.py | |
parent | 2230bcfe24d6b28719aa6ef1c483a619e1960b6a (diff) | |
download | cpython-c226c311392abbda437300eaa9841d9e839854c0.zip cpython-c226c311392abbda437300eaa9841d9e839854c0.tar.gz cpython-c226c311392abbda437300eaa9841d9e839854c0.tar.bz2 |
Let pprint() support sets and frozensets (suggested by David Mertz).
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r-- | Lib/pprint.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index 89f99d2..9359de3 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -162,11 +162,24 @@ class PrettyPrinter: write('}') return - if (issubclass(typ, list) and r is list.__repr__) or \ - (issubclass(typ, tuple) and r is tuple.__repr__): + if ((issubclass(typ, list) and r is list.__repr__) or + (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): write('[') 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: write('(') endchar = ')' |