[Python-ideas] Should decimal.InvalidOperation subclass ValueError?
stefan at bytereef.org
Mon May 23 04:11:10 EDT 2016
Greg Ewing <greg.ewing 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?
For Decimal at least, Overflow, Underflow, Clamped etc. don't really
map to ValueError.
This includes InvalidOperation, which unfortunately *already* has
a subclass ConversionSyntax for the use case that came up here.
ConversionSyntax, however, is designated by the standard to be a
"condition" rather than a "signal", so ConversionSyntax isn't
raised -- it just exists, and in the C version you can see the
"condition" in the list next to the exception that was raised.
Adding a ValueError to all that just complicates things further.
I wouldn't mind raising ConversionSyntax directly, but then again
no one knows about that either and it's a small deviation from
More information about the Python-ideas