[docs] [issue17309] __bytes__ doesn't work in subclass of int and str
Terry J. Reedy
report at bugs.python.org
Sat Mar 2 00:03:39 CET 2013
Terry J. Reedy added the comment:
More data:
class myit(list):
def __bytes__(self): return b'hello'
print (bytes(b'a'))
class myit(list):
def __bytes__(self): return b'hello'
print (bytearray (myit([1,2,3])))
# bytearray(b'a')
# bytearray(b'\x01\x02\x03')
class by:
def __bytes__(self): return b'hello'
# TypeError: 'by' object is not iterable
(Error message is incomplete.)
So bytearray *always* treats objects as specified in its library entry and never calls __bytes__, making its value sometimes unequal as a sequence of bytes from bytes with the same input.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17309>
_______________________________________
More information about the docs
mailing list