cpython: 976de10bf731 (original) (raw)

--- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -283,6 +283,36 @@ class PrettyPrinter: _dispatch[str.repr] = _pprint_str

+

+

+

+ def _format_dict_items(self, items, stream, indent, allowance, context, level): write = stream.write @@ -463,5 +493,22 @@ def _perfcheck(object=None): print("_safe_repr:", t2 - t1) print("pformat:", t3 - t2) +def _wrap_bytes_repr(object, width, allowance):

+ if name == "main": _perfcheck()

--- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -658,6 +658,106 @@ frozenset2({0, self.assertLessEqual(maxwidth, w) self.assertGreater(maxwidth, w - 3)

+(b'abcdefghijkl'

+(b'abcdefghijkl'

+(b'abcdefghijkl'

+(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b'

+(b'\x00\x01\x02\x03'

+(b'\x00\x01\x02\x03'

+{'a': 1,

+{'a': 1,

+[[[[[[b'abcdefghijklmnop'

+[[[[[[b'\x00\x01\x02\x03\x04\x05\x06\x07'

+

+bytearray(b'abcdefghijkl'

+bytearray(b'abcdefghijkl'

+bytearray(b'abcdefghijkl'

+bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b'

+bytearray(b'\x00\x01\x02\x03'

+bytearray(b'\x00\x01\x02\x03'

+{'a': 1,

+[[[[[bytearray(b'abcdefghijklmnop'

+[[[[[bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07'

+ class DottedPrettyPrinter(pprint.PrettyPrinter):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -26,6 +26,8 @@ Core and Builtins Library ------- +- Issue #17530: pprint now wraps long bytes objects and bytearrays. +