Python 3 __bytes__ method

Ethan Furman ethan at stoneleaf.us
Sat Jan 11 21:44:55 EST 2014


On 01/11/2014 06:19 PM, Daniel da Silva wrote:
>
> One use case is:
> Suppose you have existing function that accepts a /bytes/ object. If you subclass /bytes/ and want it to be guaranteed
> to work with that function, you can override/__bytes__()/ to use the logistics of your subclass implementation.

I don't think so, for two reasons:

1) bytes objects do not have a __bytes__ method,

2) if the function is expecting a bytes object, it is unlikely to call bytes() on it.

--
~Ethan~



More information about the Python-list mailing list