Re: [Python-Dev] 3.1 and 2.7 break format() when used with complex (sometimes)

2010-02-23 Thread Eric Smith
The root cause of this problem is object.__format__, which is basically: def __format__(self, fmt): return str(self).__format__(fmt) So here we're changing the type of the object (to str) but still keeping the same format string. That doesn't make any sense: the format string is type specifi

Re: [Python-Dev] 3.1 and 2.7 break format() when used with complex (sometimes)

2010-02-22 Thread Eric Smith
Eric Smith wrote: This code works on 2.6 and 3.0: >>> format(1+1j, '10s') '(1+1j)' That's because format ends up calling object.__format__ because complex doesn't have its own __format__. Then object.__format__ calls str(self) which returns '(1+1j)'. So the original call basically tur

[Python-Dev] 3.1 and 2.7 break format() when used with complex (sometimes)

2010-02-22 Thread Eric Smith
This code works on 2.6 and 3.0: >>> format(1+1j, '10s') '(1+1j)' That's because format ends up calling object.__format__ because complex doesn't have its own __format__. Then object.__format__ calls str(self) which returns '(1+1j)'. So the original call basically turns into "format('(1