← index #3158Issue #1109
Off-topic · high · value 2.299
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 · ISSUE

Limited special method support for classes inherited from native types

closedby slush0opened 2015-02-09updated 2024-08-28

class bytes_(bytes): pass
bytes() + bytes_()
TypeError: unsupported types for add: 'bytes', 'bytes_'

This passes in python3 without problem.

Goal: I'm missing some extended functionality in built-in types (like bytes.translate), so I wanted to patch them by pure python implementation in overloaded class. Of course I can implement them in separate object instead, but it's missing a beauty of transparency.

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