← index #3158PR #4181
Off-topic · high · value 1.130
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/objstr: format: Return bytes result for bytes format string.

closedby pfalconopened 2018-09-22updated 2018-09-26
This is an improvement over previous behavior when str was returned for
both str and bytes input format. This is also consistent with how % operator and
many other str/bytes methods work.

It should be noted that it's not how current versions of CPython work,
where there's a gap in the  functionality and bytes.format() is not
supported.

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