
On 11 March 2014 21:58, Ethan Furman <ethan@stoneleaf.us> wrote:
On 03/11/2014 02:51 PM, random832@fastmail.us wrote:
The bug to which I was referring involves not calling __format__ on whatever object is passed in as str.format does - Decimal not being float is no impediment to str.format and Decimal.__format__ accepting the same format strings that float.__format__ does.
That is not a bug. str.__mod__ is not documented as calling an object's __format__ method, and indeed it does not.
Instead it calls float on the object:
class A: ... def __float__(self): ... print('__float__ called') ... '%f' % A() __float__ called Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: nb_float should return float object
There's no mention of that anywhere in the docs though: http://docs.python.org/3.4/library/stdtypes.html#printf-style-string-formatt... There's also no mention of this in the decimal docs. Oscar