[New-bugs-announce] [issue26208] decimal C module's exceptions don't match the Python version
Petr Viktorin
report at bugs.python.org
Tue Jan 26 12:46:59 EST 2016
New submission from Petr Viktorin:
Exceptions from the decimal module are quite unfriendly:
>>> Decimal(42) / Decimal(0)
...
decimal.DivisionByZero: [<class 'decimal.DivisionByZero'>]
>>> huge = Decimal('9' * 99)
>>> huge.quantize(Decimal('0.1'))
...
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]
compared to the pure Python implementation:
decimal.DivisionByZero: x / 0
decimal.InvalidOperation: quantize result has too many digits for current context
If I'm reading http://bugs.python.org/issue21227 right, the exception argument is a of signals, and indicates the complete set of signals raised by the operation. However, this is (AFAICS) not documented, and not portable (since it's not present in the Python version).
I believe this behavior should be
- either dropped in favor of friendlier error messages (or possibly moved to a more internal attribute of the exception, and documented as an optional CPython feature),
- or documented, and implemented in _pydecimal as well.
Which of those actions would be right seems to be a question of whether the exception argument is part of the API.
----------
components: Library (Lib)
messages: 258965
nosy: encukou, skrah
priority: normal
severity: normal
status: open
title: decimal C module's exceptions don't match the Python version
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26208>
_______________________________________
More information about the New-bugs-announce
mailing list