Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Lib/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ def _pprint_dataclass(self, object, stream, indent, allowance, context, level):

def _pprint_dict(self, object, stream, indent, allowance, context, level):
write = stream.write
write('{')
typ = object.__class__
if typ is frozendict:
stream.write(typ.__name__ + '({')
end = '})'
indent += len(typ.__name__) + 1
else:
write('{')
end = '}'
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
length = len(object)
Expand All @@ -231,9 +238,10 @@ def _pprint_dict(self, object, stream, indent, allowance, context, level):
items = object.items()
self._format_dict_items(items, stream, indent, allowance + 1,
context, level)
write('}')
write(end)

_dispatch[dict.__repr__] = _pprint_dict
_dispatch[frozendict.__repr__] = _pprint_dict

def _pprint_ordered_dict(self, object, stream, indent, allowance, context, level):
if not len(object):
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ def test_basic_line_wrap(self):
for type in [dict, dict2]:
self.assertEqual(pprint.pformat(type(o)), exp)

exp = """\
frozendict({'RPM_cal': 0,
'RPM_cal2': 48059,
'Speed_cal': 0,
'controldesk_runtime_us': 0,
'main_code_runtime_us': 0,
'read_io_runtime_us': 0,
'write_io_runtime_us': 43690})"""
self.assertEqual(pprint.pformat(frozendict(o)), exp)

o = range(100)
exp = 'dict_keys([%s])' % ',\n '.join(map(str, o))
keys = dict.fromkeys(o).keys()
Expand Down
Loading