Serhiy Storchaka added the comment: printf-style bytes formatting was added mainly for increasing compatibility with Python 2. It was restricted to support mostly features existing in Python 2.
'%s' formatting in Python 3 supports bytes-like objects partially: >>> b'%s' % array('B', [1, 2]) "array('B', [1, 2])" >>> b'%s' % buffer(array('B', [1, 2])) '\x01\x02' >>> b'%s' % memoryview(array('B', [1, 2])) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: cannot make memory view because object does not have the buffer interface >>> b'%s' % bytearray(b'abc') 'abc' >>> b'%s' % buffer(bytearray(b'abc')) 'abc' >>> b'%s' % memoryview(bytearray(b'abc')) '<memory at 0xb70902ac>' I don't know whether there is a need of supporting the buffer protocol in printf-style bytes formatting. bytearray is already supported, buffer() doesn't exist in Python 3, memoryview() is not supported in Python 2. Seems this doesn't add anything for increasing the compatibility. ---------- nosy: +skrah _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28856> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com