New submission from rech <r.rechkem...@web.de>:

A common pattern is to check numeric input like this:

a = input()
try:
   int(a) # or float(a)
except ValueError:
   print("Bad input")

One would expect this to work with decimal.Decimal(a), too. But, as
Decimal.__init__ raises decimal.InvalidOperation instead of a
ValueError, it fails.

Making Decimal.__init__ raise a ValueError in this context would be an
incompatible change. Also, making decimal.InvalidOperation a subclass of
ValueError might not be correct.
It would be best to create a new an more specific exception for this
case, a subclass of both decimal.InvalidOperation and ValueError. This
would keep all functionality and enable this kind of intuitive use.

----------
components: Library (Lib)
messages: 79814
nosy: lemburg, rech
severity: normal
status: open
title: decimal.Decimal.__init__ should raise an instance of ValueError
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue4940>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to