[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3 (original) (raw)
Ethan Furman ethan at stoneleaf.us
Wed Mar 26 17:47:25 CET 2014
- Previous message: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3
- Next message: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 03/26/2014 08:14 AM, Thomas Wouters wrote:
On Tue, Mar 25, 2014 at 11:37 PM, Ethan Furman wrote:
In particular,
%s
will not accept numbers (use a numeric format code for that), norstr
(encode it tobytes
).I don't understand this restriction, and there isn't a rationale for it in the PEP (other than "you can already use numeric formats", which doesn't explain why it's undesirable to have it anyway.) It is extremely common in existing 2.x code to use %s for anything
And that's the problem -- in 2.x %s works always, but 3.x for bytes and bytearray %s will fail in numerous situations.
It seems to me the main reason for using %s instead of %d is that 'some_var' may have a number, or it may have the textual representation of that number; in 3.x the first would succeed, the second would fail. That's the kind of intermittent failure we do not want.
The PEP is not designed to make it so 2.x code can be ported as-is, but rather that 2.x code can be cleaned up (if necessary) and then run the same in both 2.x and 3.x (at least as far as byte and bytearray %-formatting is concerned).
Did this come up in the earlier discussions?
https://mail.python.org/pipermail/python-dev/2014-January/131576.html
--
Ethan
- Previous message: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3
- Next message: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]