[Python-ideas] Should decimal.InvalidOperation subclass ValueError?
Steven D'Aprano
steve at pearwood.info
Tue May 24 11:45:07 EDT 2016
On Mon, May 23, 2016 at 12:56:40PM +1000, Nick Coghlan wrote:
> On 23 May 2016 at 08:34, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> > Related to this, is there any good reason that ArithmeticError
> > doesn't derive from ValueError?
[...]
> I considered suggesting that, but got stuck on the question of how we
> quantify the compatibility implications - such a shift would change
> the behaviour of code that catches both, but handles them differently.
The same applies to decimal.InvalidOperation. Code like:
try: ...
except ValueError: ...
except InvalidOperation: ...
would change under my suggestion.
> While I can honestly say I've never seen an except clause catching
> ArithmeticError directly in the wild, I see more of a risk in the fact
> we'd potentially be silently changing the way ZeroDivisionError and
> OverflowError are handled.
>
> That said, this feels like the *right* answer to me, it's just the
> compatibility risk that worries me.
Indeed.
--
Steve
More information about the Python-ideas
mailing list