On 01/19/2014 03:37 AM, Steven D'Aprano wrote: > On Fri, Jan 17, 2014 at 05:51:05PM -0800, Ethan Furman wrote: >> On 01/17/2014 05:27 PM, Steven D'Aprano wrote: > >>>> Numeric Format Codes >>>> -------------------- >>>> >>>> To properly handle int and float subclasses, int(), index(), and float() >>>> will be called on the objects intended for (d, i, u), (b, o, x, X), and >>>> (e, E, f, F, g, G). >>> >>> >>> -1 on this idea. >>> >>> This is a rather large violation of the principle of least surprise, and >>> radically different from the behaviour of Python 3 str. In Python 3, >>> '%d' interpolation calls the __str__ method, so if you subclass, you can >>> get the behaviour you want: >> >> Did you read the bug reports I linked to? This behavior (which is a bug) >> has already been fixed for Python3.4. > > No I didn't. This thread is huge, and it's only one of a number of huge > threads about the same "bytes/unicode Python 2/3" stuff. I'm probably > not the only person who missed the bug reports you linked to. Fair point. > If these bug reports are relevant to the PEP, you ought to list them in > the PEP, and if they aren't relevant, I shan't be reading them *wink* <mischievous grin> Well, it seems to me they are more relevant to your misunderstanding of how %d and friends should work rather than to the PEP itself. However, I suppose it possible you're not the only one so affected, so I'll link them in. </mischeivous grin> > In any case, whether I have succeeded in making the case against this > aspect of the PEP or not Not. This was a bug that was fixed long before the PEP came into existence. >> As a quick thought experiment, why does "%d" % True return "1"? > > I don't know. Perhaps it is a bug? To summarize a rather long issue, %d and friends are /numeric/ codes; returning non-numeric text is inappropriate. Yes, I realize there are other unicode values than also mean numeric digits, but they do not mean (so far as I know) Decimal digits, or Hexadecimal digits, or Octal digits. (Obviously an ASCII slant going on there.) Now that I've written that down, I think there are, in fact, other scripts that represent a base-10 number system with obviously different glyphs for the numbers.... Well, that means that this PEP just further strengthens the notion that format is for text (as then a custom numeric type could easily override the display even for :d, :h, etc.) and % is for bytes (where such glyphs are not natively representable anyway). -- ~Ethan~
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4