[New-bugs-announce] [issue33055] bytes does not implement __bytes__()

FHTMitchell report at bugs.python.org
Mon Mar 12 10:28:02 EDT 2018


New submission from FHTMitchell <fergus.htm at gmail.com>:

Every object which has a corresponding dunder protocol also implements said protocol with one exception:


>>> 'hello'.__str__()
'hello'

>>> (3.14).__float__()
3.14

>>> (101).__int__()
101

>>> True.__bool__()
True

>>> iter(range(10)).__iter__()
<range_iterator at 0xf6b08b0>

>>> b'hello'.__bytes__()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
----> 1 b'hello'.__bytes__()

AttributeError: 'bytes' object has no attribute '__bytes__'

This was brought up on SO as being inconsistent: https://stackoverflow.com/questions/49236655/bytes-doesnt-have-bytes-method/49237034?noredirect=1#comment85477673_49237034

----------
components: Interpreter Core
messages: 313653
nosy: FHTMitchell
priority: normal
severity: normal
status: open
title: bytes does not implement __bytes__()
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33055>
_______________________________________


More information about the New-bugs-announce mailing list