diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-09-07 18:04:58 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-09-07 18:04:58 (GMT) |
commit | 968f1690d39e8c825f9af1b634ff5b5a9517c290 (patch) | |
tree | 83dc220e8505efdf3738039831b8b334738740db /Lib/decimal.py | |
parent | 491ea55f2866cc0b4fee036069fc07748920b0cf (diff) | |
download | cpython-968f1690d39e8c825f9af1b634ff5b5a9517c290.zip cpython-968f1690d39e8c825f9af1b634ff5b5a9517c290.tar.gz cpython-968f1690d39e8c825f9af1b634ff5b5a9517c290.tar.bz2 |
#Issue 6795: Fix infinite recursion in long(Decimal('nan')); change int(Decimal('nan')) to raise ValueError instead of either returning NaN or raising InvalidContext.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index 1f5c920..a87a4a5 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1555,10 +1555,9 @@ class Decimal(object): """Converts self to an int, truncating if necessary.""" if self._is_special: if self._isnan(): - context = getcontext() - return context._raise_error(InvalidContext) + raise ValueError("Cannot convert NaN to integer") elif self._isinfinity(): - raise OverflowError("Cannot convert infinity to int") + raise OverflowError("Cannot convert infinity to integer") s = (-1)**self._sign if self._exp >= 0: return s*int(self._int)*10**self._exp |