mirror of
https://github.com/python/cpython.git
synced 2025-11-20 02:50:14 +00:00
#Issue 6795: Fix infinite recursion in long(Decimal('nan')); change int(Decimal('nan')) to raise ValueError instead of either returning NaN or raising InvalidContext.
This commit is contained in:
parent
491ea55f28
commit
968f1690d3
3 changed files with 16 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue