[issue15136] Decimal accepting Fraction
Terry J. Reedy
report at bugs.python.org
Sat Jun 23 10:11:08 CEST 2012
Terry J. Reedy <tjreedy at udel.edu> added the comment:
I think *both* proposals are sensible. Fraction already has .from_decimal (using Decimal), so .to_decimal (also using Decimal) is sensible. It also has .from_float, with 'f.to_float' spelled f.__float__, normally called as float(f).
On the other hand, part of the point of the new format system was/is to allow 'other' classes to tie into format specs with custom .__format__. Currently, Fraction inherits .__format__ from object, which only recognizes 's' specifications. (Anything else gives a misleading 'str' error message that is the subject of another issue.) I think it should get a custom .__format__, which could use f.to_decimal(prec), where prec is calculated from the format spec.
----------
nosy: +eric.smith, terry.reedy
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15136>
_______________________________________
More information about the Python-bugs-list
mailing list