This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients belopolsky, ethan.furman, serhiy.storchaka, skrah, xiang.zhang
Date 2017-03-07.11:16:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1488885383.54.0.651469001823.issue28856@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-03-07 11:16:23serhiy.storchakasetrecipients: + serhiy.storchaka, belopolsky, skrah, ethan.furman, xiang.zhang
2017-03-07 11:16:23serhiy.storchakasetmessageid: <1488885383.54.0.651469001823.issue28856@psf.upfronthosting.co.za>
2017-03-07 11:16:23serhiy.storchakalinkissue28856 messages
2017-03-07 11:16:23serhiy.storchakacreate