diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-24 21:47:56 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-24 21:47:56 (GMT) |
commit | 5310b6941965afa3a40e61e8315590c931dc47e6 (patch) | |
tree | 348d42382940aac520f612fedb87326dbfebe634 /Lib/pprint.py | |
parent | 6170874f9c16b45a60851821c599898f51ba02d2 (diff) | |
download | cpython-5310b6941965afa3a40e61e8315590c931dc47e6.zip cpython-5310b6941965afa3a40e61e8315590c931dc47e6.tar.gz cpython-5310b6941965afa3a40e61e8315590c931dc47e6.tar.bz2 |
Shorter pprint's for empty sets and frozensets. Fix indentation of frozensets. Add tests including two complex data structures.
Diffstat (limited to 'Lib/pprint.py')
-rw-r--r-- | Lib/pprint.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index 9359de3..9f9d6a2 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -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 |