Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014年1月15日 08:06:25 -0800

On 2014年1月15日 15:47:43 +0000 (UTC)
Neil Schemenauer <[email protected]> wrote:
> 
> Objects that implement __str__ can also implement __bytes__ if they
> can guarantee that ASCII characters are always returned, no matter
> what the *value*
I think that's a slippery slope. __bytes__ should mean that the object
has a well-known bytes equivalent or encoding, not that its __str__
happens to be pure ASCII.
(for example, it would be fine for a HTTP message class to define a
__bytes__ method)
Also, consider that if e.g. float had a __bytes__ method, then
bytes(2.0) would start returning b'2.0', while bytes(2) would still
need to return b'\x00\x00'.
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to