Message255593
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 |
|
Date |
User |
Action |
Args |
2015-11-29 20:26:42 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka |
2015-11-29 20:26:42 | serhiy.storchaka | set | messageid: <1448828802.95.0.345172708456.issue25766@psf.upfronthosting.co.za> |
2015-11-29 20:26:42 | serhiy.storchaka | link | issue25766 messages |
2015-11-29 20:26:42 | serhiy.storchaka | create | |
|