[issue27492] Enhance bytearray_repr with bytes_repr's logic
Serhiy Storchaka
report at bugs.python.org
Mon Aug 15 06:44:51 EDT 2016
Serhiy Storchaka added the comment:
The two function's advantage is in the ability to reuse this code for other purposes. For example in _codecs.escape_encode(). But since this is the only place where the same algorithm is used and this functions is not documented and I presume it is not much used, this advantage is pretty small.
The simplest implementation of bytearray.__repr__ is
def __repr__(self):
return 'bytearray(%r)' % bytes(self)
It is less efficient than the current implementation or proposed patch, but is much simpler. This approach is used in reprs of set, frozenset, deque, array, BaseException, itemgetter, attrgetter, etc.
It can be more efficient is make bytes.__repr__ accepting not only bytes, but objects supporting the buffer protocol.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27492>
_______________________________________
More information about the Python-bugs-list
mailing list