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 <[email protected]>
<http://bugs.python.org/issue27492>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com