Merged revisions 74708 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74708 | mark.dickinson | 2009-09-07 19:04:58 +0100 (Mon, 07 Sep 2009) | 2 lines
#Issue 6795: Fix infinite recursion in long(Decimal('nan')); change int(Decimal('nan')) to raise ValueError instead of either returning NaN or raising InvalidContext.
........
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 4108fb8..4324430 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -1512,10 +1512,9 @@
"""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