This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: decimal.Decimal("trash") produces informationless exception
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: facundobatista Nosy List: facundobatista, nnorwitz, sjmachin
Priority: normal Keywords:

Created on 2007-08-08 12:44 by sjmachin, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg32596 - (view) Author: John Machin (sjmachin) Date: 2007-08-08 12:44
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> decimal.Decimal("-$123,456.78")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python25\lib\decimal.py", line 614, in __new__
    self._sign, self._int, self._exp = context._raise_error(ConversionSyntax)
  File "C:\python25\lib\decimal.py", line 2325, in _raise_error
    raise error, explanation
decimal.InvalidOperation

It should do something like float does ... better message, and show the offending arg:

>>> float("-$123,456.78")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for float(): -$123,456.78
>>>
msg32597 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-08-10 03:36
Facundo, could you take a look?
msg32598 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2007-08-13 15:17
Yes, I will.
msg32599 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2007-08-15 15:14
Fixed, both in trunk and in the decimal-branch:

>>> import decimal
>>> decimal.Decimal("-$123,456.78")
Traceback (most recent call last):
...
decimal.InvalidOperation: Invalid literal for Decimal: '-$123,456.78'
>>> 
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45288
2007-08-08 12:44:32sjmachincreate