[Python-Dev] PEP 460 reboot (original) (raw)
Guido van Rossum guido at python.org
Mon Jan 13 01:47:15 CET 2014
- Previous message: [Python-Dev] PEP 460 reboot
- Next message: [Python-Dev] PEP 460 reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Jan 12, 2014 at 4:28 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
On 01/12/2014 03:55 PM, Guido van Rossum wrote:
There's a lot of discussion about PEP 460 and I haven't read it all. Maybe you all have already reached the same conclusion that I have. No, no agreement has been reached. Your contribution is timely.
PEP 460 itself currently rejects support for %d, AFAIK on the basis that bytes aren't necessarily ASCII. I think that's a misunderstanding of the intention of the bytes type. [...] this does not mean the bytes type isn't allowed to have a noticeable bias in favor of encodings that are ASCII supersets, even if not all bytes objects contain such data [...] IMO it's totally fine and consistent if b'%d' % 42 returns b'42' and also for b'{}'.format(42) to return b'42' [...]
- byte literals: b'abc' (it's a syntax error to have a non-ASCII character here) - the upper() and lower() methods modify the ASCII letter positions - int(b'42') == 42, float(b'3.14') == 3.14 So if we allow the numeric modifiers [1], the only remaining question is do we allow %c and %s, and if so how do they behave? Guido?
Yes, all the numeric formatting codes such as %x, %o, %e, %f, %g should all work, as should the padding, justification and and related modifiers. E.g. b'%4x' %10 should return b' a'.
%c looks simple enough too: With an int it should insert one byte, insisting that the value is in range(256). With a bytes argument the length should be 1. (I note that I can't remember ever using %c -- it's just there because it's in C.)
%s seems the trickiest: I think with a bytes argument it should just insert those bytes (and the padding modifiers should work too), and for other types it should probably work like %a, so that it works as expected for numeric values, and with a string argument it will return the ascii()-variant of its repr(). Examples:
b'%s' % 42 == b'42' b'%s' % 'x' == b"'x'" (i.e. the three-byte string containing an 'x' enclosed in single quotes)
I have to admin I didn't know about ascii(). It's nifty. :-)
--
Ethan[1] modifiers is not the right word for %i, %x, etc, is it? What is the correct term?
I'd interpret "modifiers" as the stuff that can go between the % and the format letter, e.g. %04d or %-.3s. The term I'd use for %i, %x etc would be numeric formatting codes.
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] PEP 460 reboot
- Next message: [Python-Dev] PEP 460 reboot
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]