Stefan Krah added the comment: I agree with Mark's arguments. Yesterday I tried to use as_decimal() in a small program and it did not feel natural to me. I'll probably continue to use Decimal(f.numerator) / f.denominator.
If this goes in, I'd prefer that as_decimal() always uses a localcontext(). As the patch stands, using as_decimal() pollutes the global context flags, which can be quite unexpected: >>> from fractions import Fraction as F >>> F(1, 3).as_decimal() Decimal('0.3333333333333333333333333333') >>> >>> import decimal >>> decimal.getcontext() Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, capitals=1, clamp=0, flags=[Inexact, Rounded], traps=[InvalidOperation, DivisionByZero, Overflow]) >>> If the function takes a context argument, it might be better to move it into the decimal module as Decimal.from_fraction(context). So I'm -1/7 on as_decimal(), but +1 for the __format__() method. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15136> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com