This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients serhiy.storchaka
Date 2015-11-29.20:26:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1448828802.95.0.345172708456.issue25766@psf.upfronthosting.co.za>
In-reply-to
Content
Special __bytes__ method is purposed for converting to bytes with bytes constructor (as well as __str__ and __float__ for str and float). But this doesn't work if the class is a subclass of str.

>>> class X:
...     def __bytes__(self):
...         return b'abc'
... 
>>> bytes(X())
b'abc'
>>> class Y(str):
...     def __bytes__(self):
...         return b'abc'
... 
>>> bytes(Y())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string argument without an encoding
History
Date User Action Args
2015-11-29 20:26:42serhiy.storchakasetrecipients: + serhiy.storchaka
2015-11-29 20:26:42serhiy.storchakasetmessageid: <1448828802.95.0.345172708456.issue25766@psf.upfronthosting.co.za>
2015-11-29 20:26:42serhiy.storchakalinkissue25766 messages
2015-11-29 20:26:42serhiy.storchakacreate