diff -r a8df1ca60452 Lib/pprint.py --- a/Lib/pprint.py Mon Feb 23 00:31:33 2015 +0200 +++ b/Lib/pprint.py Mon Feb 23 21:10:16 2015 +0200 @@ -36,6 +36,7 @@ saferepr() import re import sys as _sys +import types as _types from collections import OrderedDict as _OrderedDict from io import StringIO as _StringIO @@ -271,6 +272,15 @@ class PrettyPrinter: if level == 1: write(')') return + + if (issubclass(typ, _types.MappingProxyType) and + r is _types.MappingProxyType.__repr__): + write('mappingproxy(') + self._format(object.copy(), stream, indent + 13, allowance + 1, + context, level) + write(')') + return + write(rep) def _format_dict_items(self, items, stream, indent, allowance, context, diff -r a8df1ca60452 Lib/test/test_pprint.py --- a/Lib/test/test_pprint.py Mon Feb 23 00:31:33 2015 +0200 +++ b/Lib/test/test_pprint.py Mon Feb 23 21:10:16 2015 +0200 @@ -7,6 +7,7 @@ import test.test_set import random import collections import itertools +import types # list, tuple and dict subclasses that do or don't overwrite __repr__ class list2(list): @@ -271,6 +272,34 @@ class QueryTestCase(unittest.TestCase): 'a': 6, 'lazy': 7, 'dog': 8}""") + + def test_mapping_proxy(self): + words = 'the quick brown fox jumped over a lazy dog'.split() + d = dict(zip(words, itertools.count())) + m = types.MappingProxyType(d) + self.assertEqual(pprint.pformat(m), """\ +mappingproxy({'a': 6, + 'brown': 2, + 'dog': 8, + 'fox': 3, + 'jumped': 4, + 'lazy': 7, + 'over': 5, + 'quick': 1, + 'the': 0})""") + d = collections.OrderedDict(zip(words, itertools.count())) + m = types.MappingProxyType(d) + self.assertEqual(pprint.pformat(m), """\ +mappingproxy({'the': 0, + 'quick': 1, + 'brown': 2, + 'fox': 3, + 'jumped': 4, + 'over': 5, + 'a': 6, + 'lazy': 7, + 'dog': 8})""") + def test_subclassing(self): o = {'names with spaces': 'should be presented using repr()', 'others.should.not.be': 'like.this'}