Unsupported operator for Decimal: + (or -)

Chris Mellon arkanes at gmail.com
Tue Nov 27 13:00:46 EST 2007


On Nov 27, 2007 11:45 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> This seems to have come up earlier...
>
> http://mail.python.org/pipermail/python-list/2007-July/451187.html
>
> but no resolution.
>
> We're seeing the same thing. We're using Django's DecimalField type
> and when we try to add or subtract values--which should be
> decimal.Decimal objects--we occasionally get an error about the
> operator not being supported. It doesn't always happen and we can't
> seem to reproduce it when we try to.
>
> Has anybody else seen this or is it just the original poster and me?
>

If __sub__ (or __add__, or whatever) returns NotImplemented that can
raise this error. This should never happen between two Decimal
instances, and the traceback should show you which two classes were
used. The most likely cause is that something is getting passed into
the comparison that's not a Decimal, an int, or a long.



More information about the Python-list mailing list