[Python-ideas] duck typing for io write methods
Wolfgang Maier
wolfgang.maier at biologie.uni-freiburg.de
Sun Jun 16 22:51:06 CEST 2013
Benjamin Peterson <benjamin at ...> writes:
>
> Wolfgang Maier <wolfgang.maier <at> ...> writes:
>
> > However, if you decide to inherit from str or int, then bytes() completely
> > ignores the __bytes__ method and sticks to the superclass behavior instead,
> > i.e. requiring an encoding for str and creating a bytestring of the length
> > of an int.
>
> int is fixed in 3.3.
>
Ah right, I found this now as Issue17309 at bugs.python.org, and you're
saying there that it's been fixed. I just tested int with Python3.3.0 on
Windows and it still ignores __bytes__. Which exact version are you
referring to?
class bint (int):
def __bytes__(self):
return b'now bytes'
a=bint(4)
bytes(a)
-> b'\x00\x00\x00\x00'
Best,
Wolfgang
More information about the Python-ideas
mailing list