NotImplemented used in Decimal

Kushal Kumaran kushal.kumaran+python at gmail.com
Fri Apr 23 23:35:14 EDT 2010


On Sat, Apr 24, 2010 at 8:54 AM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> I'm reading the source code for decimal.Decimal, and I see that the
> arithmetic operations (__add__, __sub__, etc.) start with code like this:
>
>        if other is NotImplemented:
>            return other
>
>
> I don't understand the purpose of this. I presume that it is *not* for
> the use-case of:
>
> d = Decimal('123.456')
> result = d + NotImplemented
>
> which not only doesn't make sense to me, but when I try it, it raises
> TypeError. So I find myself confused why the arithmetic methods do this.
>

There's a _convert_other method which is called before the test that
can return NotImplemented.

-- 
regards,
kushal



More information about the Python-list mailing list