Python: Inheritance from bytes-class

Viewed 96

I created a class that inherits from the 'bytes'-class.

class A(bytes):
    def __init__(self, data):
        super().__init__()

    @property
    def a(self):
        return self[0]

    @property
    def b(self):
        return self[1]

The initialiser of class A does not explicitly pass the data-argument to the base class.

c = A(b'\x12\x34')
print(hex(c.a), hex(c.b))

And the output is

0x12 0x34

How can this code work?

0 Answers
Related