Message97268
> What about the idea of changing the implementation from:
>
> return a.__add__(b, context=self)
>
> to
>
> return Decimal(a+b,context=self)
> ?
I think it would be better to convert the arguments a and b to Decimal before doing the addition. In the case of addition, it doesn't make much difference: for integers a and b, Decimal(a+b) rounded to the current context should be the same as Decimal(a) + Decimal(b). But for e.g., division, Decimal(a/b) is potentially different from Decimal(a)/Decimal(b).
There's also the issue that the context methods can return 'NotImplemented'. For example:
Python 2.7a1+ (trunk:77217:77234, Jan 2 2010, 15:45:27)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import *
>>> C = getcontext()
>>> C.add(Decimal(3), 'not a number')
NotImplemented
It's possible that a TypeError would make more sense here: NotImplemented should really only be returned by direct invocation of the double underscore magic methods (__add__, etc.).
Any patch should include tests in Lib/test/test_decimal.py, of course! |
|
Date |
User |
Action |
Args |
2010-01-05 17:49:25 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, facundobatista, jjconti, skrah |
2010-01-05 17:49:24 | mark.dickinson | set | messageid: <1262713764.93.0.9242048644.issue7633@psf.upfronthosting.co.za> |
2010-01-05 17:49:22 | mark.dickinson | link | issue7633 messages |
2010-01-05 17:49:22 | mark.dickinson | create | |
|