[issue15882] _decimal.Decimal constructed from tuple

Stefan Krah report at bugs.python.org
Sat Sep 8 08:50:46 CEST 2012


Stefan Krah added the comment:

Infinities do not have payloads. It's a bug in decimal.py that it
accepts non-empty coefficients when constructing infinities.

Since there was a corresponding unit test for as_tuple(), I've
kept the wrong representation for _decimal:

    # XXX non-compliant infinity payload.
    d = Decimal("Infinity")
    self.assertEqual(d.as_tuple(), (0, (0,), 'F') )


But this unit test is only executed for the Python version:

    # XXX coefficient in infinity should raise an error
    if self.decimal == P:
        d = Decimal( (0, (4, 5, 3, 4), 'F') )
        self.assertEqual(d.as_tuple(), (0, (0,), 'F'))
        d = Decimal( (1, (0, 2, 7, 1), 'F') )
        self.assertEqual(d.as_tuple(), (1, (0,), 'F'))


My suggestion is to disallow non-empty tuples for decimal.py
and change the infinity tuple to (0, (), 'F').

----------
nosy: +mark.dickinson

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15882>
_______________________________________


More information about the Python-bugs-list mailing list