← index #3158PR #4771
Off-topic · high · value 0.691
QUERY · ISSUE

py: bytes() won't call obj.__bytes__()

openby ThunderEXopened 2017-06-21updated 2024-08-28
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/objarray: Add decode method to bytearray.

closedby stinosopened 2019-05-09updated 2019-05-21

Reuse the implementation for bytes since it's exactly the same.

Also found this when working with msgpack where it gets used to get strings instead of bytes, which is too convenient not to use it (e.g. msgpack.unpackb(msgpack.packb('a')) returns b'a' without it). I don' think there is an easy way around here (like dynamically adding a method to a builtin type)?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied