Constructor mistake when overloading builtin type "bytes"

1 week ago 2
ARTICLE AD BOX

here is a very simple snippet that shows by problem :

class MyBytes ( bytes ): def __init__(self,buffer,nb): self[:] = bytes( buffer )*nb b = MyBytes( b'123',5 )

When I run it, it get this error :

b = MyBytes( b'123',5 ) ^^^^^^^^^^^^^^^^^^^ TypeError: bytes() argument 'encoding' must be str, not int

It's like if my overload of the constructor was ignored...
Maybe there is trick when overloading a builtin type ?
Any idea ?
Thanx in advance

Read Entire Article