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

2014-02-26 Thread Stephen J. Turnbull
Nick Coghlan writes: > sjt writes: > > although introduction of a new format character is a poor man's > > consistency, and this is consistency for consistency's sake. (I don't > > have a big problem with that, though. I *like* consistency!) > > It's *not* a new format character, unless y

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

2014-02-25 Thread Nick Coghlan
On 26 February 2014 13:57, Stephen J. Turnbull wrote: > Nick Coghlan writes that b'%a' is > > > the obvious way to interpolate representations of arbitrary objects > > into binary formats that contain ASCII compatible segments. > > The only argument that I have sympathy for is > > > %a *should*

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

2014-02-25 Thread Stephen J. Turnbull
Nick Coghlan writes that b'%a' is > the obvious way to interpolate representations of arbitrary objects > into binary formats that contain ASCII compatible segments. The only argument that I have sympathy for is > %a *should* be allowed for consistency with text interpolation although introd

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

2014-02-25 Thread Nick Coghlan
On 25 February 2014 17:43, Stuart Bishop wrote: > On 23 February 2014 08:56, Ethan Furman wrote: > >> ``%a`` will call :func:``ascii()`` on the interpolated value's >> :func:``repr()``. >> This is intended as a debugging aid, rather than something that should be >> used >> in production. Non-asc

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

2014-02-24 Thread Stuart Bishop
On 23 February 2014 08:56, Ethan Furman wrote: > ``%a`` will call :func:``ascii()`` on the interpolated value's > :func:``repr()``. > 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 > ``\unnn

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

2014-02-24 Thread Ethan Furman
On 02/24/2014 02:33 PM, Nick Coghlan wrote: Allowing %a also improves the consistency with text interpolation. In the case of %r, the inconsistency is based on needing to disallow arbitrary Unicode code points in the result and not wanting to redefine %r as a second way to spell %a. There's no

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

2014-02-24 Thread Antoine Pitrou
On Tue, 25 Feb 2014 08:33:53 +1000 Nick Coghlan wrote: > As far as use cases go, as someone else mentioned, the main one is likely > to be binary logging and error reporting formats, as it becomes a quick and > easy way to embed a backslash escaped string. That's a fringe use case, though. Also,

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

2014-02-24 Thread Nick Coghlan
On 25 Feb 2014 05:44, "Antoine Pitrou" wrote: > > On Mon, 24 Feb 2014 10:40:46 -0800 > Ethan Furman wrote: > > > Okay, types corrected, most comments taken into account. > > > > %b is right out, %a is still suffering scrutiny. > > > > The arguments seem to boil down to: > > > > We don't need it.

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

2014-02-24 Thread Victor Stinner
2014-02-24 22:08 GMT+01:00 Jim J. Jewett : >>> Will ascii() ever emit an antislash representation? Sorry, it's chr(0x10): >>> print(ascii(chr(0x10))) '\U0010' Victor ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/

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

2014-02-24 Thread Jim J. Jewett
Victor Stinner wrote: >> Will ascii() ever emit an antislash representation? > Try ascii(chr(0x1f)). In which version? I get: ValueError: chr() arg not in range(0x11) > How do you plan to use this output? Write it into a socket or a file? > When I debug, I use print & logging w

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

2014-02-24 Thread Ethan Furman
On 02/24/2014 11:54 AM, Mark Lawrence wrote: On 24/02/2014 18:40, Ethan Furman wrote: So, any last thoughts about %a? I placed it under your nose https://mail.python.org/pipermail/python-dev/2014-January/131636.html but personally I wouldn't lose any sleep whether it stays or goes. So you

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

2014-02-24 Thread Mark Lawrence
On 24/02/2014 18:40, Ethan Furman wrote: Okay, types corrected, most comments taken into account. %b is right out, %a is still suffering scrutiny. The arguments seem to boil down to: We don't need it. vs Somebody might, and it's better than having them inappropriately add a __bytes__ method

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

2014-02-24 Thread Antoine Pitrou
On Mon, 24 Feb 2014 10:40:46 -0800 Ethan Furman wrote: > Okay, types corrected, most comments taken into account. > > %b is right out, %a is still suffering scrutiny. > > The arguments seem to boil down to: > > We don't need it. > > vs > > Somebody might, and it's better than having them ina

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

2014-02-24 Thread Glenn Linderman
On 2/24/2014 10:40 AM, Ethan Furman wrote: Somebody might, and it's better than having them inappropriately add a __bytes__ method if we don't have it. I'll admit my first thought on reading the initial discussions about adding bytes % formatting was "Oh, if I want to display custom objects

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

2014-02-24 Thread Ethan Furman
Okay, types corrected, most comments taken into account. %b is right out, %a is still suffering scrutiny. The arguments seem to boil down to: We don't need it. vs Somebody might, and it's better than having them inappropriately add a __bytes__ method if we don't have it. "We don't need it"

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

2014-02-24 Thread Antoine Pitrou
On Mon, 24 Feb 2014 09:58:30 -0800 Ethan Furman wrote: > On 02/24/2014 09:43 AM, Antoine Pitrou wrote: > > On Mon, 24 Feb 2014 09:15:29 -0800 > > Ethan Furman wrote: > >> On 02/23/2014 02:54 PM, Nick Coghlan wrote: > >>> > >>> It's a harm containment tactic, based on the assumption people *will*

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

2014-02-24 Thread Ethan Furman
On 02/24/2014 09:43 AM, Antoine Pitrou wrote: On Mon, 24 Feb 2014 09:15:29 -0800 Ethan Furman wrote: On 02/23/2014 02:54 PM, Nick Coghlan wrote: It's a harm containment tactic, based on the assumption people *will* want to include the output of ascii() in binary protocols containing ASCII s

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

2014-02-24 Thread Antoine Pitrou
On Mon, 24 Feb 2014 09:15:29 -0800 Ethan Furman wrote: > On 02/23/2014 02:54 PM, Nick Coghlan wrote: > > > > It's a harm containment tactic, based on the assumption people *will* > > want to include the output of ascii() in binary protocols containing > > ASCII segments, regardless of whether or

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

2014-02-24 Thread Ethan Furman
On 02/23/2014 02:54 PM, Nick Coghlan wrote: It's a harm containment tactic, based on the assumption people *will* want to include the output of ascii() in binary protocols containing ASCII segments, regardless of whether or not we consider their reasons for doing so to be particularly good. O

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

2014-02-24 Thread Victor Stinner
2014-02-24 3:45 GMT+01:00 Nick Coghlan : > Would leaving %a out destroy the utility of the PEP? Usually, debug code is not even commited. So writing b'var=%s' % ascii(var).encode() is not hard. Or maybe: b'var=%s' % repr(var).encode('ascii', 'backslashreplace') which is the same but longer :-) V

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

2014-02-23 Thread Nick Coghlan
On 24 February 2014 08:56, Cameron Simpson wrote: > On 23Feb2014 22:56, Victor Stinner wrote: >> > An aid to debugging -- need to see what's what at that moment? Toss it >> > into %a. It is not intended for production code, but is included to >> > hopefully circumvent the inappropriate use of _

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

2014-02-23 Thread Stephen J. Turnbull
Glenn Linderman writes: > On 2/23/2014 2:25 PM, Antoine Pitrou wrote: >> On Sun, 23 Feb 2014 14:14:55 -0800 Glenn Linderman >> wrote: >>> On 2/23/2014 1:37 PM, Antoine Pitrou wrote: And you certainly*don't* print debugging output into a wire protocol. >>> Web server applications do,

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

2014-02-23 Thread Glenn Linderman
On 2/23/2014 2:25 PM, Antoine Pitrou wrote: On Sun, 23 Feb 2014 14:14:55 -0800 Glenn Linderman wrote: On 2/23/2014 1:37 PM, Antoine Pitrou wrote: And you certainly*don't* print debugging output into a wire protocol. Web server applications do, so they can be displayed in the browser. They m

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

2014-02-23 Thread Eric V. Smith
On 2/23/2014 4:25 PM, Ethan Furman wrote: > I agree that having only one decimal format code would be nice, or even > two if the second one did something different, and that three seems > completely over the top -- unfortunately, Python 3.4 still supports all > three (%d, %i, and %u). Not supportin

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

2014-02-23 Thread Antoine Pitrou
On Mon, 24 Feb 2014 08:54:08 +1000 Nick Coghlan wrote: > > > The idea being if we offer %a, folks won't be tempted to abuse > __bytes__. > > > > Which folks are we talking about? This sounds gratuitous. > > It's a harm containment tactic, based on the assumption people *will* want > to include th

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

2014-02-23 Thread Cameron Simpson
On 23Feb2014 22:56, Victor Stinner wrote: > > An aid to debugging -- need to see what's what at that moment? Toss it > > into %a. It is not intended for production code, but is included to > > hopefully circumvent the inappropriate use of __bytes__ methods on classes. > > How do you plan to use

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

2014-02-23 Thread Nick Coghlan
On 24 Feb 2014 07:39, "Antoine Pitrou" wrote: > > On Sun, 23 Feb 2014 12:42:59 -0800 > Ethan Furman wrote: > > On 02/23/2014 03:33 AM, Antoine Pitrou wrote: > > > On Sat, 22 Feb 2014 17:56:50 -0800 > > > Ethan Furman wrote: > > >> > > >> ``%a`` will call :func:``ascii()`` on the interpolated val

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

2014-02-23 Thread Antoine Pitrou
On Sun, 23 Feb 2014 14:14:55 -0800 Glenn Linderman wrote: > On 2/23/2014 1:37 PM, Antoine Pitrou wrote: > > And you certainly*don't* print debugging output into a wire protocol. > > Web server applications do, so they can be displayed in the browser. They may embed debugging information into so

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

2014-02-23 Thread Glenn Linderman
On 2/23/2014 1:37 PM, Antoine Pitrou wrote: And you certainly*don't* print debugging output into a wire protocol. Web server applications do, so they can be displayed in the browser. ___ Python-Dev mailing list Python-Dev@python.org https://mail.pyth

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

2014-02-23 Thread Victor Stinner
> > >>> >> (You forgot "/U" representation (it's an antislah, but I don't >> see the key on my Mac keyboard?).) >> > > Hard to forget what you don't know. ;) Will ascii() ever emit an > antislash representation? Try ascii(chr(0x1f)). What is the use case of this *new* formatter? H

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

2014-02-23 Thread Antoine Pitrou
On Sun, 23 Feb 2014 12:42:59 -0800 Ethan Furman wrote: > On 02/23/2014 03:33 AM, Antoine Pitrou wrote: > > On Sat, 22 Feb 2014 17:56:50 -0800 > > Ethan Furman wrote: > >> > >> ``%a`` will call :func:``ascii()`` on the interpolated value's > >> :func:``repr()``. > >> This is intended as a debuggi

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

2014-02-23 Thread Ethan Furman
On 02/23/2014 03:30 AM, Victor Stinner wrote: First, this is a warning in reST syntax: System Message: WARNING/2 (pep-0461.txt, line 53) Yup, fixed that. This area of programming is characterized by a mixture of binary data and ASCII compatible segments of text (aka ASCII-encoded text). B

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

2014-02-23 Thread Ethan Furman
On 02/23/2014 03:33 AM, Antoine Pitrou wrote: On Sat, 22 Feb 2014 17:56:50 -0800 Ethan Furman wrote: ``%a`` will call :func:``ascii()`` on the interpolated value's :func:``repr()``. This is intended as a debugging aid, rather than something that should be used in production. Non-ascii values

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

2014-02-23 Thread Ethan Furman
On 02/22/2014 10:50 PM, Nikolaus Rath wrote: Ethan Furman writes: Example:: >>> b'%4x' % 10 b' a' >>> '%#4x' % 10 ' 0xa' >>> '%04X' % 10 '000A' Shouldn't the second two examples also be bytes, ie. b'%#4x' instead of '%#4x'? Yup, thanks. -- ~Ethan~ _

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

2014-02-23 Thread Ethan Furman
On 02/23/2014 03:31 AM, Antoine Pitrou wrote: On Sat, 22 Feb 2014 20:48:04 -0800 Ethan Furman wrote: All the numeric formatting codes (such as ``%x``, ``%o``, ``%e``, ``%f``, ``%g``, etc.) will be supported, and will work as they do for str, including the padding, justification and other relate

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

2014-02-23 Thread Nikolaus Rath
Ethan Furman writes: > Example:: > >>>> b'%4x' % 10 >b' a' > >>>> '%#4x' % 10 >' 0xa' > >>>> '%04X' % 10 >'000A' Shouldn't the second two examples also be bytes, ie. b'%#4x' instead of '%#4x'? Best, -Nikolaus -- Encrypted emails preferred. PGP fingerprint: 5B93 61F8

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

2014-02-23 Thread Cameron Simpson
On 23Feb2014 12:30, Victor Stinner wrote: > > All the numeric formatting codes (such as ``%x``, ``%o``, ``%e``, ``%f``, > > ``%g``, etc.) will be supported, and will work as they do for str, including > > the padding, justification and other related modifiers. > > IMO you should give the exhausti

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

2014-02-23 Thread Cameron Simpson
On 23Feb2014 16:31, Nick Coghlan wrote: > On 23 February 2014 13:47, Cameron Simpson wrote: > > On 22Feb2014 17:56, Ethan Furman wrote: > >> Please let me know if anything else needs tweaking. > >> [...] > >> This area of programming is characterized by a mixture of binary data and > >> ASCII co

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

2014-02-23 Thread Victor Stinner
Hi, First, this is a warning in reST syntax: System Message: WARNING/2 (pep-0461.txt, line 53) > This area of programming is characterized by a mixture of binary data and > ASCII compatible segments of text (aka ASCII-encoded text). Bringing back a > restricted %-interpolation for ``bytes`` and

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

2014-02-23 Thread Antoine Pitrou
On Sat, 22 Feb 2014 17:56:50 -0800 Ethan Furman wrote: > > ``%a`` will call :func:``ascii()`` on the interpolated value's > :func:``repr()``. > 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

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

2014-02-23 Thread Antoine Pitrou
On Sat, 22 Feb 2014 20:48:04 -0800 Ethan Furman wrote: > On 02/22/2014 07:47 PM, Cameron Simpson wrote: > > On 22Feb2014 17:56, Ethan Furman wrote: > >> Please let me know if anything else needs tweaking. > >> [...] > >> This area of programming is characterized by a mixture of binary data and >

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

2014-02-22 Thread Nick Coghlan
Thanks Ethan, this mostly looks excellent. On 23 February 2014 11:56, Ethan Furman wrote: > ``%a`` will call :func:``ascii()`` on the interpolated value's > :func:``repr()``. > This is intended as a debugging aid, rather than something that should be > used > in production. Non-ascii values will

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

2014-02-22 Thread Nick Coghlan
On 23 February 2014 13:47, Cameron Simpson wrote: > On 22Feb2014 17:56, Ethan Furman wrote: >> Please let me know if anything else needs tweaking. >> [...] >> This area of programming is characterized by a mixture of binary data and >> ASCII compatible segments of text (aka ASCII-encoded text). >

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

2014-02-22 Thread Ethan Furman
On 02/22/2014 07:47 PM, Cameron Simpson wrote: On 22Feb2014 17:56, Ethan Furman wrote: Please let me know if anything else needs tweaking. [...] This area of programming is characterized by a mixture of binary data and ASCII compatible segments of text (aka ASCII-encoded text). [...] %-interpol

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

2014-02-22 Thread Ethan Furman
On 02/22/2014 07:29 PM, Mark Lawrence wrote: On 23/02/2014 02:30, Ethan Furman wrote: +be any more of a nuisance than the already existing methdods. Typo "methdods". Thanks, fixed. -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org http

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

2014-02-22 Thread Cameron Simpson
On 22Feb2014 17:56, Ethan Furman wrote: > Please let me know if anything else needs tweaking. > [...] > This area of programming is characterized by a mixture of binary data and > ASCII compatible segments of text (aka ASCII-encoded text). > [...] > %-interpolation > > All the numeric formatting

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

2014-02-22 Thread Mark Lawrence
On 23/02/2014 02:30, Ethan Furman wrote: +be any more of a nuisance than the already existing methdods. Typo "methdods". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware

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

2014-02-22 Thread Chris Angelico
On Sun, Feb 23, 2014 at 12:56 PM, Ethan Furman wrote: > Open Questions > == > > It has been suggested to use ``%b`` for bytes as well as ``%s``. > > - Pro: clearly says 'this is bytes'; should be used for new code. > > - Con: does not exist in Python 2.x, so we would have two ways

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

2014-02-22 Thread Ethan Furman
Sorry, found a couple more comments in a different thread. Here's what I added: +Objections +== + +The objections raised against this PEP were mainly variations on two themes:: + + - the ``bytes`` and ``bytearray`` types are for pure binary data, with no +assumptions about encodings

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

2014-02-22 Thread Ethan Furman
Greetings, all! I think I'm about ready to ask for pronouncement for this PEP, but I would like opinions on the Open Questions question so I can close it. :) Please let me know if anything else needs tweaking. -- PEP: 461 Title: Adding % f