Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Nick Coghlan
On 18 Jan 2014 06:19, "Terry Reedy" wrote: > > On 1/17/2014 10:15 AM, Mark Lawrence wrote: > >> For both options 1 and 2 surely you cannot be suggesting that after >> people have written 2.x code to use format() as %f formatting is to be >> deprecated, > > > I will not be for at least a decade. I

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Terry Reedy
Responding to two posts at once, as I consider them On 1/17/2014 11:00 AM, Brett Cannon wrote: I would rephrase it to "switch to %-formatting for bytes usage for their common code base". If they are working with actual text then using str.format() still works (and is actually nicer to use IMO).

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Terry Reedy
On 1/17/2014 10:15 AM, Mark Lawrence wrote: For both options 1 and 2 surely you cannot be suggesting that after people have written 2.x code to use format() as %f formatting is to be deprecated, I will not be for at least a decade. they now have to change the code back to the way they may we

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric V. Smith
On 01/17/2014 02:04 PM, Glenn Linderman wrote: > On 1/17/2014 7:15 AM, Mark Lawrence wrote: >> For both options 1 and 2 surely you cannot be suggesting that after >> people have written 2.x code to use format() as %f formatting is to be >> deprecated, they now have to change the code back to the wa

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Glenn Linderman
On 1/17/2014 7:15 AM, Mark Lawrence wrote: For both options 1 and 2 surely you cannot be suggesting that after people have written 2.x code to use format() as %f formatting is to be deprecated, they now have to change the code back to the way they may well have written it in the first place?

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Glenn Linderman
On 1/17/2014 6:50 AM, Eric V. Smith wrote: Following up, I think this leaves us with 3 choices: 1. Do not implement bytes.format(). We tell any 2.x code that's written to use str.format() to switch to %-formatting for their common code base. 2. Add the simplistic version of bytes.format() that

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Ethan Furman
On 01/17/2014 09:13 AM, Eric V. Smith wrote: On 01/17/2014 11:58 AM, Brett Cannon wrote: On Fri, Jan 17, 2014 at 11:16 AM, Barry Warsaw wrote: On Jan 17, 2014, at 11:00 AM, Brett Cannon wrote: I would rephrase it to "switch to %-formatting for bytes usage for their common code base". -1. %

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric V. Smith
On 01/17/2014 11:58 AM, Brett Cannon wrote: > > > > On Fri, Jan 17, 2014 at 11:16 AM, Barry Warsaw > wrote: > > On Jan 17, 2014, at 11:00 AM, Brett Cannon wrote: > > >I would rephrase it to "switch to %-formatting for bytes usage for > their > >common

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Brett Cannon
On Fri, Jan 17, 2014 at 11:16 AM, Barry Warsaw wrote: > On Jan 17, 2014, at 11:00 AM, Brett Cannon wrote: > > >I would rephrase it to "switch to %-formatting for bytes usage for their > >common code base". > > -1. %-formatting is so neanderthal. :) > Very much so, which is why I'm willing to le

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Ethan Furman
On 01/16/2014 11:47 PM, Steven D'Aprano wrote: On Thu, Jan 16, 2014 at 08:23:13AM -0800, Ethan Furman wrote: As I understand it, str.format will call the object's __format__. So, for example, if I say: u'the value is: %d' % myNum(17) then it will be myNum.__format__ that gets called, not

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Nick Coghlan
On 18 Jan 2014 02:08, "Paul Moore" wrote: > > On 17 January 2014 15:50, Eric V. Smith wrote: > > For #3, hopefully this "additional work" on the 3.x side would just be > > to add, to each class where you already have a custom __format__ used > > for b''.format(), code like: > > > > def __form

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Barry Warsaw
On Jan 17, 2014, at 11:00 AM, Brett Cannon wrote: >I would rephrase it to "switch to %-formatting for bytes usage for their >common code base". -1. %-formatting is so neanderthal. :) -Barry ___ Python-Dev mailing list Python-Dev@python.org https://mai

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Paul Moore
On 17 January 2014 15:50, Eric V. Smith wrote: > For #3, hopefully this "additional work" on the 3.x side would just be > to add, to each class where you already have a custom __format__ used > for b''.format(), code like: > > def __format_ascii__(self, fmt): > return self.__format__(f

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Brett Cannon
On Fri, Jan 17, 2014 at 9:50 AM, Eric V. Smith wrote: > On 01/17/2014 07:34 AM, Eric V. Smith wrote: > > On 1/17/2014 6:42 AM, Nick Coghlan wrote: > >> > >> On 17 Jan 2014 18:03, "Eric Snow" >> > wrote: > >>> > >>> On Thu, Jan 16, 2014 at 11:30 AM, Eric V. Smi

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Mark Lawrence
On 17/01/2014 15:41, Ethan Furman wrote: On 01/17/2014 07:15 AM, Mark Lawrence wrote: For both options 1 and 2 surely you cannot be suggesting that after people have written 2.x code to use format() as %f formatting is to be deprecated %f formatting is not deprecated, and will not be in 3.x'

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric V. Smith
On 01/17/2014 10:24 AM, Eric V. Smith wrote: > On 01/17/2014 10:15 AM, Mark Lawrence wrote: >> On 17/01/2014 14:50, Eric V. Smith wrote: >>> On 01/17/2014 07:34 AM, Eric V. Smith wrote: On 1/17/2014 6:42 AM, Nick Coghlan wrote: > > On 17 Jan 2014 18:03, "Eric Snow"

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Ethan Furman
On 01/17/2014 07:15 AM, Mark Lawrence wrote: For both options 1 and 2 surely you cannot be suggesting that after people have written 2.x code to use format() as %f formatting is to be deprecated %f formatting is not deprecated, and will not be in 3.x's lifetime. -- ~Ethan~ __

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric V. Smith
On 01/17/2014 10:15 AM, Mark Lawrence wrote: > On 17/01/2014 14:50, Eric V. Smith wrote: >> On 01/17/2014 07:34 AM, Eric V. Smith wrote: >>> On 1/17/2014 6:42 AM, Nick Coghlan wrote: On 17 Jan 2014 18:03, "Eric Snow" >>> > wrote: > > On Thu, Jan

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Mark Lawrence
On 17/01/2014 14:50, Eric V. Smith wrote: On 01/17/2014 07:34 AM, Eric V. Smith wrote: On 1/17/2014 6:42 AM, Nick Coghlan wrote: On 17 Jan 2014 18:03, "Eric Snow" mailto:ericsnowcurren...@gmail.com>> wrote: On Thu, Jan 16, 2014 at 11:30 AM, Eric V. Smith > wrote:

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric V. Smith
On 01/17/2014 07:34 AM, Eric V. Smith wrote: > On 1/17/2014 6:42 AM, Nick Coghlan wrote: >> >> On 17 Jan 2014 18:03, "Eric Snow" > > wrote: >>> >>> On Thu, Jan 16, 2014 at 11:30 AM, Eric V. Smith > > wrote: For the first iteration

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric V. Smith
On 1/17/2014 6:42 AM, Nick Coghlan wrote: > > On 17 Jan 2014 18:03, "Eric Snow" > wrote: >> >> On Thu, Jan 16, 2014 at 11:30 AM, Eric V. Smith > wrote: >> > For the first iteration of bytes.format(), I think we should just >> > suppo

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Nick Coghlan
On 17 Jan 2014 18:03, "Eric Snow" wrote: > > On Thu, Jan 16, 2014 at 11:30 AM, Eric V. Smith wrote: > > For the first iteration of bytes.format(), I think we should just > > support the exact types of int, float, and bytes. It will call the > > type's__format__ (with the object as "self") and enc

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric Snow
On Thu, Jan 16, 2014 at 3:06 PM, Jan Kaliszewski wrote: > I'd treat the format()+.__format__()+str.format()-"ecosystem" as > a nice text-data-oriented, *complete* Py3k feature, backported to > Python 2 to share the benefits of the feature with it as well as > to make the 2-to-3 transition a bit ea

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-17 Thread Eric Snow
On Thu, Jan 16, 2014 at 11:30 AM, Eric V. Smith wrote: > For the first iteration of bytes.format(), I think we should just > support the exact types of int, float, and bytes. It will call the > type's__format__ (with the object as "self") and encode the result to > ASCII. For the stated use case o

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Steven D'Aprano
On Thu, Jan 16, 2014 at 08:23:13AM -0800, Ethan Furman wrote: > As I understand it, str.format will call the object's __format__. So, for > example, if I say: > > u'the value is: %d' % myNum(17) > > then it will be myNum.__format__ that gets called, not int.__format__; I seem to have misse

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Jan Kaliszewski
16.01.2014 17:33, Michael Urman wrote: On Thu, Jan 16, 2014 at 8:45 AM, Brett Cannon wrote: Fine, if you're worried about bytes.format() overstepping by implicitly calling str.encode() on the return value of __format__() then you will need __bytes__format__() to get equivalent support. Cou

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Eric V. Smith
On 01/16/2014 01:55 PM, Ethan Furman wrote: >> "Magic" methods, including __format__, are called on the type, not the >> instance. > > Yes, that's why I said `myNum(17)` and not `myNum`. Oops, apologies. I misread the code. Eric. ___ Python-Dev maili

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Ethan Furman
On 01/16/2014 10:30 AM, Eric V. Smith wrote: On 01/16/2014 11:23 AM, Ethan Furman wrote: On 01/16/2014 06:45 AM, Brett Cannon wrote: But that's **only** because the numeric types choose to as part of their __format__() implementation; it is not inherent to str.format(). As I understand it, s

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Eric V. Smith
On 01/16/2014 11:23 AM, Ethan Furman wrote: > On 01/16/2014 06:45 AM, Brett Cannon wrote: >> On Thu, Jan 16, 2014 at 2:51 AM, Ethan Furman wrote: >>> On 01/15/2014 06:45 AM, Brett Cannon wrote: This is why I have argued that if you specify it as "if there is a format spec specified,

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Glenn Linderman
On 1/16/2014 8:41 AM, Brett Cannon wrote: That's a very good catch, Michael! I think that makes sense if there is precedence. Unfortunately that bit from the PEP never made it into the documentation so I'm not sure if there is a backwards-compatibility worry. No. If __format__ is called with

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Michael Urman
On Thu, Jan 16, 2014 at 11:13 AM, Neil Schemenauer wrote: > A TypeError exception is what we want if the object does not support > bytes formatting. Some possible problems: > > - It could be hard to provide a helpful exception message since it > is generated inside the __format__ method rather

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Neil Schemenauer
Michael Urman wrote: > If __format__ receives a format_spec of type bytes, it should return > bytes. For such cases on objects that cannot support bytes (i.e. for > str), it can raise. This appears to avoid the need for additional > methods. (As does Nick's proposal of leaving it out for now.) Th

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Brett Cannon
On Thu, Jan 16, 2014 at 11:33 AM, Michael Urman wrote: > On Thu, Jan 16, 2014 at 8:45 AM, Brett Cannon wrote: > > Fine, if you're worried about bytes.format() overstepping by implicitly > > calling str.encode() on the return value of __format__() then you will > need > > __bytes__format__() to g

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Ethan Furman
On 01/16/2014 06:45 AM, Brett Cannon wrote: On Thu, Jan 16, 2014 at 2:51 AM, Ethan Furman wrote: On 01/15/2014 06:45 AM, Brett Cannon wrote: This is why I have argued that if you specify it as "if there is a format spec specified, then the return value from calling __format__() will have str

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Michael Urman
On Thu, Jan 16, 2014 at 8:45 AM, Brett Cannon wrote: > Fine, if you're worried about bytes.format() overstepping by implicitly > calling str.encode() on the return value of __format__() then you will need > __bytes__format__() to get equivalent support. Could we just re-use PEP-3101's note (easil

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Neil Schemenauer
Greg Ewing wrote: > Neil Schemenauer wrote: >> Objects that implement __str__ can also implement __bytes__ if they >> can guarantee that ASCII characters are always returned, > > I think __ascii_ would be a better name. I'd expect > a method called __bytes__ on an int to return some > version of i

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Brett Cannon
On Thu, Jan 16, 2014 at 4:56 AM, Nick Coghlan wrote: > > On 16 Jan 2014 17:53, "Ethan Furman" wrote: > > > > On 01/15/2014 06:45 AM, Brett Cannon wrote: > >> > >> > >> This is why I have argued that if you specify it as "if there is a > format spec specified, then the return value from > >> call

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Brett Cannon
On Thu, Jan 16, 2014 at 2:51 AM, Ethan Furman wrote: > On 01/15/2014 06:45 AM, Brett Cannon wrote: > >> >> This is why I have argued that if you specify it as "if there is a format >> spec specified, then the return value from >> calling __format__() will have str.decode('ascii', 'strict') called

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Greg Ewing
Nick Coghlan wrote: I have a different proposal: let's *just* add mod formatting to bytes, and leave the extensible formatting system as a text only operation. +1 -- Greg ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mai

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-16 Thread Nick Coghlan
On 16 Jan 2014 17:53, "Ethan Furman" wrote: > > On 01/15/2014 06:45 AM, Brett Cannon wrote: >> >> >> This is why I have argued that if you specify it as "if there is a format spec specified, then the return value from >> calling __format__() will have str.decode('ascii', 'strict') called on it" yo

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 06:45 AM, Brett Cannon wrote: This is why I have argued that if you specify it as "if there is a format spec specified, then the return value from calling __format__() will have str.decode('ascii', 'strict') called on it" you get the support for the various number-specific format

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Greg Ewing
Ethan Furman wrote: Well, I'm not sure what "booted into touch" means, It's a rugby term, referring to kicking the ball over the touch line. As a metaphor, it seems to mean making a problem go away. -- Greg ___ Python-Dev mailing list Python-Dev@pyt

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Steven D'Aprano
On Wed, Jan 15, 2014 at 05:46:07PM -0800, Glenn Linderman wrote: > On 1/15/2014 4:03 PM, Steven D'Aprano wrote: > >What precisely does it do? If it's so obvious, why is this thread so > >long? > > It produces a formatted representation of the object in bytes. For > numbers, that would probably b

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Glenn Linderman
On 1/15/2014 4:03 PM, Steven D'Aprano wrote: What precisely does it do? If it's so obvious, why is this thread so long? It produces a formatted representation of the object in bytes. For numbers, that would probably be expected to be ASCII digits and punctuation. But other items are not as

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Steven D'Aprano
On Wed, Jan 15, 2014 at 10:34:48PM +, Mark Lawrence wrote: > On 15/01/2014 22:22, Brett Cannon wrote: > > > > > > > >On Wed, Jan 15, 2014 at 5:00 PM, Steven D'Aprano >> wrote: > > > >On Thu, Jan 16, 2014 at 10:55:31AM +1300, Greg Ewing wrote: > > > Neil Sche

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Mark Lawrence
On 15/01/2014 22:22, Brett Cannon wrote: On Wed, Jan 15, 2014 at 5:00 PM, Steven D'Aprano mailto:st...@pearwood.info>> wrote: On Thu, Jan 16, 2014 at 10:55:31AM +1300, Greg Ewing wrote: > Neil Schemenauer wrote: > >Objects that implement __str__ can also implement __bytes__ if t

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 08:33 AM, Mark Lawrence wrote: For completeness I believe %r and %a should be included here as well. Good point. Done. -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Un

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Brett Cannon
On Wed, Jan 15, 2014 at 5:00 PM, Steven D'Aprano wrote: > On Thu, Jan 16, 2014 at 10:55:31AM +1300, Greg Ewing wrote: > > Neil Schemenauer wrote: > > >Objects that implement __str__ can also implement __bytes__ if they > > >can guarantee that ASCII characters are always returned, > > > > I think _

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Brett Cannon
On Wed, Jan 15, 2014 at 4:24 PM, Ethan Furman wrote: > On 01/15/2014 06:45 AM, Brett Cannon wrote: > >> >> I also think that a 'b' conversion be added to bytes.format(). This >> doesn't have the same issue as %b if you make {} >> implicitly mean {!b} in Python 3.5 as {} will mean what is the most

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Eric V. Smith
On 1/15/2014 4:32 PM, Ethan Furman wrote: > A question for anyone that has extensive experience in both %-formatting > and .format-formatting: Would it be possible, at least for int and > float, to take whatever is in the specifier and convert to %? Example: > > "Weight: {wgt:-07f}".format(wgt

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Steven D'Aprano
On Thu, Jan 16, 2014 at 10:55:31AM +1300, Greg Ewing wrote: > Neil Schemenauer wrote: > >Objects that implement __str__ can also implement __bytes__ if they > >can guarantee that ASCII characters are always returned, > > I think __ascii_ would be a better name. I'd expect > a method called __bytes

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Greg Ewing
Neil Schemenauer wrote: Objects that implement __str__ can also implement __bytes__ if they can guarantee that ASCII characters are always returned, I think __ascii_ would be a better name. I'd expect a method called __bytes__ on an int to return some version of its binary value. -- Greg _

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 06:45 AM, Brett Cannon wrote: The PEP currently says:: format -- The format mini language will be used as-is, with the behaviors as listed for %-interpolation. That's too vague; % interpolation does not support other format operators in the same way as str.f

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 06:45 AM, Brett Cannon wrote: I also think that a 'b' conversion be added to bytes.format(). This doesn't have the same issue as %b if you make {} implicitly mean {!b} in Python 3.5 as {} will mean what is the most accurate for bytes.format() in either version. It also allows for

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Neil Schemenauer
Glenn Linderman wrote: > On 1/15/2014 7:52 AM, Eric V. Smith wrote: >> Either that, or we're back to encoding the result of __format__ and >> accepting that sometimes it might throw errors, depending on the values >> being passed into format(). That would take us back to Python 2 hell. Please no

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Glenn Linderman
On 1/15/2014 7:52 AM, Eric V. Smith wrote: So basically I think we'll have to hard-code the types that .format() will support, and never call __format__, or only call __format__ if we know that it's a exact type where we know that __format__ will return (strict ASCII). Either that, or we're back

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Guido van Rossum
All sounds good. A fleeting thought about constructors: you can always add alternative constructors as class methods (like datetime does). On Wed, Jan 15, 2014 at 10:09 AM, Neil Schemenauer wrote: > Antoine Pitrou wrote: >> On Wed, 15 Jan 2014 15:47:43 + (UTC) Neil S wrote: >>> >>> Objects

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Neil Schemenauer
Antoine Pitrou wrote: > On Wed, 15 Jan 2014 15:47:43 + (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

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Isaac Morland
On Wed, 15 Jan 2014, Antoine Pitrou wrote: On Wed, 15 Jan 2014 15:47:43 + (UTC) Neil Schemenauer 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

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 08:51 AM, Brett Cannon wrote: On Wed, Jan 15, 2014 at 10:57 AM, Ethan Furman wrote: Thanks for your comments. I've only barely touched format, so it's not an area of strength for me. :) Time to strengthen it if you are proposing a PEP that is going to affect it. =) I am. Y

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Brett Cannon
On Wed, Jan 15, 2014 at 10:57 AM, Ethan Furman wrote: > On 01/15/2014 06:45 AM, Brett Cannon wrote: > >> bytes.format() below. I'll leave it to you to decide if they warrant >> using, leaving as an open question, or rejecting. >> > > Thanks for your comments. I've only barely touched format, so

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Brett Cannon
On Wed, Jan 15, 2014 at 10:52 AM, Eric V. Smith wrote: > On 1/15/2014 9:45 AM, Brett Cannon wrote: > > > That's too vague; % interpolation does not support other format > > operators in the same way as str.format() does. % interpolation has > > specific code to support %d, etc. But str.format() g

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Mark Lawrence
On 14/01/2014 19:56, Ethan Furman wrote: Duh. Here's the text, as well. ;) %s, because it is the most general, has the most convoluted resolution: - input type is bytes? pass it straight through - input type is numeric? use its __xxx__ [1] [2] method and ascii-encode it (stri

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 07:47 AM, Neil Schemenauer wrote: Thanks for writing the PEP. Thank you for your comments! -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.pyth

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 08:04 AM, Antoine Pitrou wrote: On Wed, 15 Jan 2014 15:47:43 + (UTC) Neil Schemenauer 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 slo

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/14/2014 02:41 PM, Mark Lawrence wrote: On 14/01/2014 19:55, Ethan Furman wrote: This PEP goes a but further than PEP 460 does, and hopefully spells things out in enough detail so there is no confusion as to what is meant. -- ~Ethan~ Out of plain old curiosity do we have to consider PEP

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Neil Schemenauer
Neil Schemenauer wrote: > We should use duck-typing and that means a special method, I > think. We could introduce a new one but __bytes__ looks like it > can work. Otherwise, maybe __ascii__ is a good name. I poked around the Python 3 source. Using __bytes__ has some downsides, e.g. the follo

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Antoine Pitrou
On Wed, 15 Jan 2014 15:47:43 + (UTC) Neil Schemenauer 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

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Ethan Furman
On 01/15/2014 06:45 AM, Brett Cannon wrote: bytes.format() below. I'll leave it to you to decide if they warrant using, leaving as an open question, or rejecting. Thanks for your comments. I've only barely touched format, so it's not an area of strength for me. :) -- ~Ethan~ __

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Eric V. Smith
On 1/15/2014 9:45 AM, Brett Cannon wrote: > That's too vague; % interpolation does not support other format > operators in the same way as str.format() does. % interpolation has > specific code to support %d, etc. But str.format() gets supported for > {:d} not from special code but because e.g. fl

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Neil Schemenauer
This looks pretty good to me. I don't think we should limit operands based on type, that's anti-Pythonic IMHO. We should use duck-typing and that means a special method, I think. We could introduce a new one but __bytes__ looks like it can work. Otherwise, maybe __ascii__ is a good name. Object

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-15 Thread Brett Cannon
bytes.format() below. I'll leave it to you to decide if they warrant using, leaving as an open question, or rejecting. On Tue, Jan 14, 2014 at 2:56 PM, Ethan Furman wrote: > Duh. Here's the text, as well. ;) > > > PEP: 461 > Title: Adding % and {} formatting to bytes > Version: $Revision$ > L

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Ethan Furman
On 01/14/2014 05:02 PM, Glenn Linderman wrote: On 1/14/2014 2:38 PM, Nick Coghlan wrote: I think Brett has the right idea: we shouldn't try to accept numbers for %s in binary interpolation. If we limit it to just buffer exporters and objects with a __bytes__ method then the problem goes away.

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Glenn Linderman
On 1/14/2014 2:38 PM, Nick Coghlan wrote: I think Brett has the right idea: we shouldn't try to accept numbers for %s in binary interpolation. If we limit it to just buffer exporters and objects with a __bytes__ method then the problem goes away. The numeric codes all exist in Python 2, so t

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Serhiy Storchaka
15.01.14 00:40, Guido van Rossum написав(ла): I think of PEP 460 as the strict version and PEP 461 as the lenient version. I don't think it makes sense to have more variants. So please collaborate with whichever you like best. :-) Perhaps the consensus will be PEP 460.5? Or PEP 460.3, or may be

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Mark Lawrence
On 14/01/2014 19:55, Ethan Furman wrote: This PEP goes a but further than PEP 460 does, and hopefully spells things out in enough detail so there is no confusion as to what is meant. -- ~Ethan~ Out of plain old curiosity do we have to consider PEP 292 string templates in any way, shape or for

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Guido van Rossum
I think of PEP 460 as the strict version and PEP 461 as the lenient version. I don't think it makes sense to have more variants. So please collaborate with whichever you like best. :-) On Tue, Jan 14, 2014 at 1:11 PM, Ethan Furman wrote: > On 01/14/2014 01:05 PM, Brett Cannon wrote: > >> On Tue,

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Nick Coghlan
On 15 Jan 2014 08:23, "Ethan Furman" wrote: > > On 01/14/2014 02:17 PM, Nick Coghlan wrote: >> >> >> On 15 Jan 2014 07:36, "Ethan Furman" > wrote: >>> >>> >>> On 01/14/2014 12:57 PM, Antoine Pitrou wrote: On Tue, 14 Jan 2014 11:56:25 -0800 Ethan Furman mailto:et...@stoneleaf.us

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Ethan Furman
On 01/14/2014 02:17 PM, Nick Coghlan wrote: On 15 Jan 2014 07:36, "Ethan Furman" mailto:et...@stoneleaf.us>> wrote: On 01/14/2014 12:57 PM, Antoine Pitrou wrote: On Tue, 14 Jan 2014 11:56:25 -0800 Ethan Furman mailto:et...@stoneleaf.us>> wrote: %s, because it is the most general, has the

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Nick Coghlan
On 15 Jan 2014 07:36, "Ethan Furman" wrote: > > On 01/14/2014 12:57 PM, Antoine Pitrou wrote: >> >> On Tue, 14 Jan 2014 11:56:25 -0800 >> Ethan Furman wrote: >>> >>> >>> %s, because it is the most general, has the most convoluted resolution: >>> >>> - input type is bytes? >>> pass it st

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Antoine Pitrou
On Tue, 14 Jan 2014 13:07:57 -0800 Ethan Furman wrote: > > Meaning any bytes or bytes-subtype will support the Py_buffer protocol, and > this should be the first thing we try? > > Sounds good. > > For that matter, should the first test be "does this object support > Py_buffer" and not worry a

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Yury Selivanov
On January 14, 2014 at 4:36:00 PM, Ethan Furman (et...@stoneleaf.us) wrote: > > On 01/14/2014 12:57 PM, Antoine Pitrou wrote: > > On Tue, 14 Jan 2014 11:56:25 -0800 > > Ethan Furman wrote: > >> > >> %s, because it is the most general, has the most convoluted > resolution: > >> > >> - input type i

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Ethan Furman
On 01/14/2014 12:57 PM, Antoine Pitrou wrote: On Tue, 14 Jan 2014 11:56:25 -0800 Ethan Furman wrote: %s, because it is the most general, has the most convoluted resolution: - input type is bytes? pass it straight through It should try to get a Py_buffer instead. Meaning any byte

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Ethan Furman
On 01/14/2014 01:05 PM, Brett Cannon wrote: On Tue, Jan 14, 2014 at 2:55 PM, Ethan Furman wrote: This PEP goes a but further than PEP 460 does, and hopefully spells things out in enough detail so there is no confusion as to what is meant. Are we going down the PEP route with the various idea

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Brett Cannon
On Tue, Jan 14, 2014 at 2:55 PM, Ethan Furman wrote: > This PEP goes a but further than PEP 460 does, and hopefully spells things > out in enough detail so there is no confusion as to what is meant. > Are we going down the PEP route with the various ideas? Guido, do you want one from me as well

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Antoine Pitrou
On Tue, 14 Jan 2014 11:56:25 -0800 Ethan Furman wrote: > > %s, because it is the most general, has the most convoluted resolution: > >- input type is bytes? > pass it straight through It should try to get a Py_buffer instead. >- input type is numeric? > use its __xxx__ [1] [2

Re: [Python-Dev] PEP 461 - Adding % and {} formatting to bytes

2014-01-14 Thread Ethan Furman
Duh. Here's the text, as well. ;) PEP: 461 Title: Adding % and {} formatting to bytes Version: $Revision$ Last-Modified: $Date$ Author: Ethan Furman Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 2014-01-13 Python-Version: 3.5 Post-History: 2014-01-13 Resolution: Abst