TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'. Why?

Duncan Booth duncan.booth at invalid.invalid
Mon Jul 30 07:20:30 EDT 2007


Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:

> On Mon, 30 Jul 2007 03:36:33 -0700, Gilbert Fine wrote:
> 
>> This is a very strange exception raised from somewhere in our
>> program. I have no idea how this happen. And don't know how to
>> reproduce. It just occurs from time to time.
> 
> Maybe different `Decimal`\s?  Here's how to reproduce such a
> traceback: 
> 
<snip>

Or even just one Decimal type but not one which supports subtraction:

>>> class Decimal(object):
     pass

>>> a = Decimal()
>>> b = Decimal()
>>> a-b

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    a-b
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'

Another option of course is that Decimal() did support substraction but 
someone deleted it:

>>> from decimal import Decimal
>>> del Decimal.__sub__
>>> Decimal()-Decimal()

Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    Decimal()-Decimal()
TypeError: unsupported operand type(s) for -: 'Decimal' and 'Decimal'




More information about the Python-list mailing list