[issue15882] _decimal.Decimal constructed from tuple

2012-09-07 Thread Aaron
New submission from Aaron: I think I may have found a problem with the code that constructs Infinity from tuples in the C _decimal module. # pure python (3.x or 2.x) >>> decimal.Decimal( (0, (0, ), 'F')) Decimal('Infinity') # _decimal >>> decimal.Decimal( (0, (0, ), 'F')) Traceback (most recen

[issue15882] _decimal.Decimal constructed from tuple

2012-09-07 Thread STINNER Victor
Changes by STINNER Victor : -- nosy: +skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.

[issue15882] _decimal.Decimal constructed from tuple

2012-09-07 Thread Stefan Krah
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 infini

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Mark Dickinson
Mark Dickinson added the comment: > It's a bug in decimal.py that it > accepts non-empty coefficients when constructing infinities. On what grounds is it a bug? I might call it a poor design decision, but it's clearly intentional. There's even a unit test for it. --

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Stefan Krah
Stefan Krah added the comment: Mark Dickinson wrote: > On what grounds is it a bug? I might call it a poor design decision, > but it's clearly intentional. There's even a unit test for it. Maybe "bug" is not the right word. I'd call it a deviation from the specification then. Do you happen to

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Mark Dickinson
Mark Dickinson added the comment: > I'd call it a deviation from the specification then. > Do you happen to know what the intention was? Well, we're kinda outside the specification here. Rightly or wrongly, Decimal('infinity').as_tuple() was originally implemented to return (0, (0,), 'F'); I'

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Mark Dickinson
Changes by Mark Dickinson : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.py

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Stefan Krah
Stefan Krah added the comment: It's an implementation detail of decimal.py to represent infinity with a coefficient of '0' instead of the empty string: >>> Decimal("inf")._int '0' So IMO the tuple representation exposes that implementation detail. I'm still not sure why that was done or what t

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Mark Dickinson
Mark Dickinson added the comment: > So, I'd really like to deprecate the whole interface in favor of either a > read-only interface: > > x.sign -> 0 or 1 (perhaps even 1 or -1) > x.coeff -> Python integer > x.exp-> Python integer > > If x is special, raise InvalidOperation. Pe

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Mark Dickinson
Mark Dickinson added the comment: > read-only interface: > > x.sign -> 0 or 1 (perhaps even 1 or -1) > x.coeff -> Python integer > x.exp-> Python integer The only slightly awkward thing with this (for high-precision decimals) is the quadratic conversion (well, okay, perhaps s

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Stefan Krah
Stefan Krah added the comment: Mark Dickinson wrote: > > So, I'd really like to deprecate the whole interface in favor of either a > > read-only interface: > > But I think that's a different issue. Yep. I was using all this as a rationale that the current tuple interface does not matter all th

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Stefan Krah
Stefan Krah added the comment: Aaron, did you encounter this problem in a real world application? I'm asking because it would be interesting to know if people use this. Google is pretty silent on "Decimal((0, (0,), 'F'))", but perhaps that is not an ideal search term. Mark, I'm uploading a mini

[issue15882] _decimal.Decimal constructed from tuple

2012-09-08 Thread Aaron
Aaron added the comment: I did not encounter this in a regular application. I do use the decimal module, and was excited to see the adoption of a faster C version, so I was just reading through the code to see how it worked. I can't think of a situation where I would need to construct a deci

[issue15882] _decimal.Decimal constructed from tuple

2012-09-10 Thread Roundup Robot
Roundup Robot added the comment: New changeset 97e53273f423 by Stefan Krah in branch 'default': Issue #15882: Change _decimal to accept any coefficient tuple when http://hg.python.org/cpython/rev/97e53273f423 -- nosy: +python-dev ___ Python tracker <

[issue15882] _decimal.Decimal constructed from tuple

2012-09-10 Thread Stefan Krah
Stefan Krah added the comment: Thanks for the report and the patch. I used another approach that still validates the digits in the coefficient tuple even if it is not used. decimal.py allows any coefficient: >>> Decimal((0, ('n', 'a', 'n'), 'F')) Decimal('Infinity') _decimal raises: >>> Decim

[issue15882] _decimal.Decimal constructed from tuple

2012-09-10 Thread Stefan Krah
Changes by Stefan Krah : -- resolution: -> fixed stage: -> committed/rejected ___ Python tracker ___ ___ Python-bugs-list mailing li

[issue15882] _decimal.Decimal constructed from tuple

2012-09-21 Thread Stefan Krah
Stefan Krah added the comment: Georg, *if* there is an rc3, could you add 97e53273f423 to it? The commit is a backwards compatibility fix for constructing infinities from tuples with arbitrary coefficients. If there's no rc3, the issue can just be closed as fixed. -- assignee: skrah -

[issue15882] _decimal.Decimal constructed from tuple

2012-09-21 Thread Georg Brandl
Georg Brandl added the comment: Done. -- status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue15882] _decimal.Decimal constructed from tuple

2012-09-23 Thread Roundup Robot
Roundup Robot added the comment: New changeset d22ea2aa1057 by Stefan Krah in branch 'default': Issue #15882: Change _decimal to accept any coefficient tuple when http://hg.python.org/cpython/rev/d22ea2aa1057 -- ___ Python tracker