[New-bugs-announce] [issue46866] bytes class extension with slices

Sec report at bugs.python.org
Sat Feb 26 06:37:49 EST 2022

New submission from Sec <sec at 42.org>:

When trying to extend the builtin bytes class, slices fall back to the builtin class.

class my_bytes(bytes):
  def dummy(self):
    print("dummy called")

x=my_bytes.fromhex("c0de c0de")



x.__class__ returns <class '__main__.my_bytes'> as expected.

But x[1:].__class__ returns <class 'bytes'>

components: Interpreter Core
files: bytes_test.py
messages: 414092
nosy: Sec42
priority: normal
severity: normal
status: open
title: bytes class extension with slices
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file50646/bytes_test.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list