Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-04-12 Thread Terry Reedy
On 4/12/2014 11:08 AM, Augie Fackler wrote: On Mar 29, 2014, at 2:53 PM, Gregory P. Smith mailto:g...@krypto.org>> wrote: On Thu, Mar 27, 2014 at 3:05 PM, Antoine Pitrou mailto:solip...@pitrou.net>> wrote: On Thu, 27 Mar 2014 18:47:59 + Brett Cannon mailto:bcan...@gmail.com>> wro

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-04-12 Thread Augie Fackler
On Mar 29, 2014, at 2:53 PM, Gregory P. Smith wrote: > > On Thu, Mar 27, 2014 at 3:05 PM, Antoine Pitrou wrote: > On Thu, 27 Mar 2014 18:47:59 + > Brett Cannon wrote: > > On Thu Mar 27 2014 at 2:42:40 PM, Guido van Rossum wrote: > > > > > Much better, but I'm still not happy with includi

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Terry Reedy
On 3/29/2014 8:28 PM, Nick Coghlan wrote: The "future" project already contains a full backport of a true bytes type, rather than relying on Python 2 str objects: http://python-future.org/what_else.html#bytes That project looks really nice! It seems to me that the easiest way to make any for

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Nick Coghlan
On 30 March 2014 05:01, Gregory P. Smith wrote: > > > > On Thu, Mar 27, 2014 at 3:47 AM, Victor Stinner > wrote: >> >> The PEP 461 looks good to me. It's a nice addition to Python 3.5 and >> the PEP is well defined. > > > +1 > >> >> I can help to implement it. Maybe, it would be nice to provide a

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Terry Reedy
On Thu, Mar 27, 2014 at 3:05 PM, Antoine Pitrou mailto:solip...@pitrou.net>> wrote: I think we have reached a point where adding porting-related facilities AFAIK, The only porting specific feature is %s as a synonym for %b. Not pretty, but tolerable. Otherwise, I have the impression th

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Nick Coghlan
On 30 March 2014 07:01, Ethan Furman wrote: > On 03/29/2014 11:59 AM, Antoine Pitrou wrote: > >> On Sat, 29 Mar 2014 11:53:45 -0700 "Gregory P. Smith" wrote: >>> >>> >>> I understand that sentiment but that is an unjustified fear. It is not a >>> good reason not to do it. Projects are already tryi

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Ethan Furman
On 03/29/2014 11:59 AM, Antoine Pitrou wrote: On Sat, 29 Mar 2014 11:53:45 -0700 "Gregory P. Smith" wrote: I understand that sentiment but that is an unjustified fear. It is not a good reason not to do it. Projects are already trying to port stuff today and running into roadblocks when it comes

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Glenn Linderman
On 3/29/2014 12:01 PM, Gregory P. Smith wrote: From a 2.x-3.x compatible code standpoint the above could exist but the container class constructor would be a no-op on Python 2. if sys.version_info[0] == 2: BytesFormatter = str else: class BytesFormatter: ... def __mod__ ... If done

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Gregory P. Smith
On Thu, Mar 27, 2014 at 3:47 AM, Victor Stinner wrote: > The PEP 461 looks good to me. It's a nice addition to Python 3.5 and > the PEP is well defined. > +1 > I can help to implement it. Maybe, it would be nice to provide an > implementation as a third-party party module on PyPI for Python > 2

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Antoine Pitrou
On Sat, 29 Mar 2014 11:53:45 -0700 "Gregory P. Smith" wrote: > > I understand that sentiment but that is an unjustified fear. It is not a > good reason not to do it. Projects are already trying to port stuff today > and running into roadblocks when it comes to ascii-compatible bytes > formatting

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-29 Thread Gregory P. Smith
On Thu, Mar 27, 2014 at 3:05 PM, Antoine Pitrou wrote: > On Thu, 27 Mar 2014 18:47:59 + > Brett Cannon wrote: > > On Thu Mar 27 2014 at 2:42:40 PM, Guido van Rossum > wrote: > > > > > Much better, but I'm still not happy with including %s at all. > Otherwise > > > it's accept-worthy. (How's

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-28 Thread Ethan Furman
On 03/27/2014 04:26 AM, Nick Coghlan wrote: On 27 March 2014 20:47, Victor Stinner wrote: The PEP 461 looks good to me. It's a nice addition to Python 3.5 and the PEP is well defined. +1 from me as well. One minor request is that I don't think the rationale for rejecting numbers from "%s" is

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-28 Thread Antoine Pitrou
On Thu, 27 Mar 2014 19:09:58 -0700 Ethan Furman wrote: > On 03/27/2014 03:10 PM, Greg Ewing wrote: > > R. David Murray wrote: > >> I've done the 'landmark' thing as well, in the string context; that can be > >> very useful when doing incremental test driven development. (Granted, you > >> could d

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 03:10 PM, Greg Ewing wrote: R. David Murray wrote: I've done the 'landmark' thing as well, in the string context; that can be very useful when doing incremental test driven development. (Granted, you could do that with __bytes__; Can't you do it more easily just by wrapping asci

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Greg Ewing
R. David Murray wrote: I've done the 'landmark' thing as well, in the string context; that can be very useful when doing incremental test driven development. (Granted, you could do that with __bytes__; Can't you do it more easily just by wrapping ascii() around the argument? That seems suffici

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Antoine Pitrou
On Thu, 27 Mar 2014 11:57:35 -0700 Ethan Furman wrote: > On 03/27/2014 11:41 AM, Guido van Rossum wrote: > > Much better, but I'm still not happy with including %s at all. Otherwise > > it's accept-worthy. (How's that for pressure. :-) > > FWIW, I feel the same, but the need for compatible 2/3 c

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Antoine Pitrou
On Thu, 27 Mar 2014 18:47:59 + Brett Cannon wrote: > On Thu Mar 27 2014 at 2:42:40 PM, Guido van Rossum wrote: > > > Much better, but I'm still not happy with including %s at all. Otherwise > > it's accept-worthy. (How's that for pressure. :-) > > > > But if we only add %b and leave out %s

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 11:41 AM, Guido van Rossum wrote: Much better, but I'm still not happy with including %s at all. Otherwise it's accept-worthy. (How's that for pressure. :-) FWIW, I feel the same, but the need for compatible 2/3 code bases is real. Hey, how's this? We'll let %s in, but immediat

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
I love it! On Thu, Mar 27, 2014 at 12:11 PM, Ethan Furman wrote: > On 03/27/2014 11:59 AM, Guido van Rossum wrote: > >> >> PS. I am not trying to be difficult. I honestly don't understand the use >> case yet, and the PEP doesn't do much to >> support it. >> > > How's this? > ---

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 11:59 AM, Guido van Rossum wrote: PS. I am not trying to be difficult. I honestly don't understand the use case yet, and the PEP doesn't do much to support it. How's this? Compatibility with Python 2 ==

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 11:53 AM, Guido van Rossum wrote: So what's the use case for Python 2/3 compatible code? IMO the main use case for the PEP is simply to be able to construct bytes from a combination of a template and some input that may include further bytes and numbers. E.g. in asyncio when you

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Daniel Holth
On Thu, Mar 27, 2014 at 2:53 PM, Guido van Rossum wrote: > So what's the use case for Python 2/3 compatible code? IMO the main use case > for the PEP is simply to be able to construct bytes from a combination of a > template and some input that may include further bytes and numbers. E.g. in > asyn

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Glenn Linderman
On 3/27/2014 11:59 AM, Guido van Rossum wrote: On Thu, Mar 27, 2014 at 11:52 AM, Daniel Holth > wrote: I feel not including %s is nuts. Should I write .replace('%b', '%s')? I assume you meant .replace('%s', '%b') (unless you're converting Python 3 code to Python 2

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
On Thu, Mar 27, 2014 at 11:34 AM, Ethan Furman wrote: > On 03/27/2014 11:24 AM, Guido van Rossum wrote: > >> On Thu, Mar 27, 2014 at 10:55 AM, Ethan Furman wrote: >> >>> >>> The biggest reason to use %s is to support a common code base for 2/3 >>> endeavors. >>> >> >> But it's mostly useless for

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
On Thu, Mar 27, 2014 at 11:52 AM, Daniel Holth wrote: > I feel not including %s is nuts. Should I write .replace('%b', '%s')? > I assume you meant .replace('%s', '%b') (unless you're converting Python 3 code to Python 2, which would mean you really are nuts :-). But that's not going to help for

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 11:24 AM, Guido van Rossum wrote: On Thu, Mar 27, 2014 at 10:55 AM, Ethan Furman wrote: The biggest reason to use %s is to support a common code base for 2/3 endeavors. But it's mostly useless for that purpose. In Python 2, in practice %s doesn't mean "string". [...] In Pytho

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
So what's the use case for Python 2/3 compatible code? IMO the main use case for the PEP is simply to be able to construct bytes from a combination of a template and some input that may include further bytes and numbers. E.g. in asyncio when you write an HTTP client or server you have to construct

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Daniel Holth
I feel not including %s is nuts. Should I write .replace('%b', '%s')? All I desperately need are APIs that provide enough unicode / str type safety that I get an exception when mixing them accidentally... in my own code, dynamic typing is usually a bug. As has been endlessly discussed, %s for bytes

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Brett Cannon
On Thu Mar 27 2014 at 2:42:40 PM, Guido van Rossum wrote: > Much better, but I'm still not happy with including %s at all. Otherwise > it's accept-worthy. (How's that for pressure. :-) > But if we only add %b and leave out %s then how is this going to lead to Python 2/3 compatible code since %b

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
Much better, but I'm still not happy with including %s at all. Otherwise it's accept-worthy. (How's that for pressure. :-) On Thu, Mar 27, 2014 at 11:04 AM, Ethan Furman wrote: > On 03/27/2014 10:55 AM, Ethan Furman wrote: > >> On 03/27/2014 10:29 AM, Guido van Rossum wrote: >> >>> >>> I also d

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 10:55 AM, Ethan Furman wrote: On 03/27/2014 10:29 AM, Guido van Rossum wrote: I also don't understand why we can't use %b instead of %s. AFAIK %b currently doesn't mean anything and I somehow don't expect we're likely to add it for other reasons (unless there's a proposal I'm mi

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
On Thu, Mar 27, 2014 at 10:55 AM, Ethan Furman wrote: > On 03/27/2014 10:29 AM, Guido van Rossum wrote: > >> >> I also don't understand why we can't use %b instead of %s. AFAIK %b >> currently doesn't mean anything and I somehow don't >> expect we're likely to add it for other reasons (unless the

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 10:29 AM, Guido van Rossum wrote: I also don't understand why we can't use %b instead of %s. AFAIK %b currently doesn't mean anything and I somehow don't expect we're likely to add it for other reasons (unless there's a proposal I'm missing?). Just like we use %a instead of %r to

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
Wow. I'm pretty consistent. I still like that. :-) On Thu, Mar 27, 2014 at 10:31 AM, MRAB wrote: > On 2014-03-27 15:58, Ethan Furman wrote: > >> On 03/27/2014 04:42 AM, Nick Coghlan wrote: >> >>> >>> I also seem to recall Guido saying he liked it [%a], which flipped the >>> discussion from "do

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread MRAB
On 2014-03-27 15:58, Ethan Furman wrote: On 03/27/2014 04:42 AM, Nick Coghlan wrote: I also seem to recall Guido saying he liked it [%a], which flipped the discussion from "do we have a good rationale for including it?" to "do we have a good rationale for the BDFL to ignore his instincts?". How

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
I also don't understand why we can't use %b instead of %s. AFAIK %b currently doesn't mean anything and I somehow don't expect we're likely to add it for other reasons (unless there's a proposal I'm missing?). Just like we use %a instead of %r to remind people that it's not quite the same (since it

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Guido van Rossum
Actually, I had ignored this discussion for so long that I was surprised by the outcome. My main use case isn't printing a number that may already be a string (I understand why that isn't reasonable when the output is expected to be bytes); it's printing a usually numeric value that may sometimes b

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 04:42 AM, Nick Coghlan wrote: I also seem to recall Guido saying he liked it [%a], which flipped the discussion from "do we have a good rationale for including it?" to "do we have a good rationale for the BDFL to ignore his instincts?". However, it would be up to Guido to confirm t

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Ethan Furman
On 03/27/2014 04:24 AM, Antoine Pitrou wrote: On Tue, 25 Mar 2014 15:37:11 -0700 Ethan Furman wrote: ``%a`` will call ``ascii()`` on the interpolated value. This is intended as a debugging aid, rather than something that should be used in production. Non-ASCII values will be encoded to either

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread R. David Murray
On Thu, 27 Mar 2014 12:24:49 +0100, Antoine Pitrou wrote: > On Tue, 25 Mar 2014 15:37:11 -0700 > Ethan Furman wrote: > > > > ``%a`` will call ``ascii()`` on the interpolated value. This is intended > > as a debugging aid, rather than something that should be used in production. > > Non-ASCII va

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Nick Coghlan
On 27 March 2014 21:24, Antoine Pitrou wrote: > On Tue, 25 Mar 2014 15:37:11 -0700 > Ethan Furman wrote: >> >> ``%a`` will call ``ascii()`` on the interpolated value. This is intended >> as a debugging aid, rather than something that should be used in production. >> Non-ASCII values will be enco

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Nick Coghlan
On 27 March 2014 20:47, Victor Stinner wrote: > The PEP 461 looks good to me. It's a nice addition to Python 3.5 and > the PEP is well defined. +1 from me as well. One minor request is that I don't think the rationale for rejecting numbers from "%s" is incomplete - IIRC, the problem there is that

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Antoine Pitrou
On Tue, 25 Mar 2014 15:37:11 -0700 Ethan Furman wrote: > > ``%a`` will call ``ascii()`` on the interpolated value. This is intended > as a debugging aid, rather than something that should be used in production. > Non-ASCII values will be encoded to either ``\xnn`` or ``\u`` > representation.

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-27 Thread Victor Stinner
The PEP 461 looks good to me. It's a nice addition to Python 3.5 and the PEP is well defined. I can help to implement it. Maybe, it would be nice to provide an implementation as a third-party party module on PyPI for Python 2.6-3.4. Note: I fixed a typo in your PEP (reST syntax). Victor 2014-03

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-26 Thread Ethan Furman
On 03/26/2014 02:41 PM, Victor Stinner wrote: 2014-03-26 15:35 GMT+01:00 Ethan Furman : --- Examples:: >>> b'%a' % 3.14 b'3.14' >>> b'%a' % b'abc' b'abc' This one is wrong: repr(b'abc').encode('

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-26 Thread Victor Stinner
2014-03-26 15:35 GMT+01:00 Ethan Furman : > --- > Examples:: > > >>> b'%a' % 3.14 > b'3.14' > > >>> b'%a' % b'abc' > b'abc' This one is wrong: >>> repr(b'abc').encode('ascii', 'backslashreplace') b"b'abc'"

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-26 Thread Ethan Furman
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), nor ``str`` (encode it to ``bytes``). I don't understand this restriction, and there isn't a rationale

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-26 Thread Thomas Wouters
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), nor ``str`` (encode it to ``bytes``). > I don't understand this restriction, and there isn't a rationale for it in the PEP (other than "you can already

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-26 Thread Ethan Furman
On 03/26/2014 03:10 AM, Victor Stinner wrote: 2014-03-25 23:37 GMT+01:00 Ethan Furman: ``%a`` will call ``ascii()`` on the interpolated value. I'm not sure that I understood correctly: is the "%a" format supported? The result of ascii() is a Unicode string. Does it mean that ("%a" % obj) shou

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-26 Thread Victor Stinner
2014-03-25 23:37 GMT+01:00 Ethan Furman : > ``%a`` will call ``ascii()`` on the interpolated value. I'm not sure that I understood correctly: is the "%a" format supported? The result of ascii() is a Unicode string. Does it mean that ("%a" % obj) should give the same result than ascii(obj).encode('

Re: [Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-25 Thread Daniel Holth
I love it. On Tue, Mar 25, 2014 at 6:37 PM, Ethan Furman wrote: > Okay, I included that last round of comments (from late February). > > Barring typos, this should be the final version. > > Final comments? > > - > PEP: 46

[Python-Dev] PEP 461: Adding % formatting to bytes and bytearray -- Final, Take 3

2014-03-25 Thread Ethan Furman
Okay, I included that last round of comments (from late February). Barring typos, this should be the final version. Final comments? - PEP: 461 Title: Adding % formatting to bytes and bytearray Version: $Revision$ Last-M