QUERY · ISSUE
py: bytes() won't call obj.__bytes__()
docs
I defined a class with bytes method. Calling bytes() on its instance should redirect to its bytes method, but it doesn't.
Can this be fixed?
CANDIDATE · PULL REQUEST
py/objstr: bytes(bytes_obj) is bytes_obj
py-core
Calling the bytes constructor on a bytes object returns the original bytes object. This addresses #6320 and has been tested on an ESP32, and everything seems to be working fine:
MicroPython v1.13-dirty on 2020-09-18; ESP32 module with ESP32
Type "help()" for more information.
>>> a = b"Original"
>>> b = a
>>> c = bytes(a)
>>> type(a)
<class 'bytes'>
>>> a is b
True
>>> a is c
True
>>> id(a)
1073642736
>>> id(b)
1073642736
>>> id(c)
1073642736