[Python-Dev] PEP 461 Final? (original) (raw)
Steven D'Aprano steve at pearwood.info
Sun Jan 19 12:37:45 CET 2014
- Previous message: [Python-Dev] PEP 461 Final?
- Next message: [Python-Dev] PEP 461 Final?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
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
In any case, whether I have succeeded in making the case against this aspect of the PEP or not, I think you should:
explain what you mean by "properly handle" (give an example?);
justify why b'%d' % obj should ignore any relevant overloaded methods in obj;
if there are similar, existing, examples of this (to me) surprising behaviour, you should briefly mention them;
note that there was some opposition to the suggestion;
and explain why the contrary behaviour (i.e. allowing obj to overload b'%d') is not desirable.
As a quick thought experiment, why does "%d" % True return "1"?
I don't know. Perhaps it is a bug?
-- Steven
- Previous message: [Python-Dev] PEP 461 Final?
- Next message: [Python-Dev] PEP 461 Final?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]