Issue 7047: decimal.py: NaN payload conversion (original) (raw)

decimal.py sets InvalidOperation if the payload of a NaN is too large:

c = getcontext() c.prec = 4 c.create_decimal("NaN12345") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/decimal.py", line 3797, in create_decimal "diagnostic info too long in NaN") File "/usr/lib/python2.7/decimal.py", line 3733, in _raise_error raise error(explanation) decimal.InvalidOperation: diagnostic info too long in NaN

decNumber (and fastdec) set ConversionSyntax.

This is essentially the same issue as issue 7046: the relevant lines in decimal.py read:

if d._isnan() and len(d._int) > self.prec - self._clamp:
    return self._raise_error(ConversionSyntax,
                                 "diagnostic info too long in NaN")

and again, the Context._raise_error method translates the ConversionSyntax exceptional condition to the corresponding InvalidOperation signal.

Closing as a duplicate, just so we can keep everything one place.