[Python-ideas] Should decimal.InvalidOperation subclass ValueError?

Greg Ewing greg.ewing at canterbury.ac.nz
Sun May 22 18:34:55 EDT 2016

>>Steven D'Aprano <steve at ...> writes:
>>>So I propose that InvalidOperation be changed to inherit from
>>>ValueError, to match the expected behaviour from other numeric types.

Related to this, is there any good reason that ArithmeticError
doesn't derive from ValueError?

If it did, it would fix this issue with Decimal and possibly
others as well.

I ran into this a while ago with a function like

    def convert(x, t):
          return t(x)
       except ValueError:

and found that not all numeric types raise something derived from
ValueError from their constructors.


More information about the Python-ideas mailing list