[Python-Dev] PEP 461 - Adding % and {} formatting to bytes (original) (raw)
Neil Schemenauer nas at arctrix.com
Wed Jan 15 19:09:29 CET 2014
- Previous message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Next message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Antoine Pitrou <solipsis at pitrou.net> wrote:
On Wed, 15 Jan 2014 15:47:43 +0000 (UTC) Neil S 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.
After poking around some more into the Python 3 source, I agree. It seems too late to change bytes() and bytearray(). We should have used a keyword only argument but too late now (tp_new is a mess).
I can also agree that pushing the ASCII-centric behavior into the bytes() constructor goes too far. If we limit the ASCII-centric behavior solely to % and format(), that seems a reasonable trade-off for usability. As others have argued, once you are using format codes, you are pretty clearly dealing with ASCII encoding.
I feel strongly that % and format on bytes needs to use duck-typing and not type checking. Also, formatting falures must be due to types and not due to values. If we can get agreement on these two principles, that will help guide the design.
Those principles absolutely rule out call calling encode('ascii') automatically. I'm not deeply intimate with format() but I think it also rules out calling format.
Could we introduce only bformat and have the % operator call it? That would only require implementing one new special method instead of two.
Neil
- Previous message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Next message: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]