New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect Decimal-float behavior for += and *= #42587
Comments
The += and *= operators have strange behavior when the Example: >>> d = Decimal('1.02')
>>> d += 2.1
>>> d
NotImplemented A blatant violation of "Errors should never pass silently." Also, a bad error description is produced for the *= >>> d = Decimal('1.02')
>>> d *= 2.9
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can't multiply sequence by non-int |
Logged In: YES Hmmm. __add__ returns NotImplemented which works with |
Logged In: YES The += and *= operations also give the same strange behavior >>> d = Decimal("1.0")
>>> d += "5"
>>> d
NotImplemented
>>> d = Decimal("1.0")
>>> d *= "1.0"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: can't multiply sequence by non-int |
Logged In: YES Facundo, can you look into this? Are you still working on |
Logged In: YES Regarding problem 1: Nick also detected this behaviour, back in March Even knowing this, Raymond Hettinger and I made a patch As Neil Schemenauer proposed And look at this: >>> d
Decimal("1") # using decimal.py rev. 39328 from svn
>>> d + 1.2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'Decimal' and
'float'
>>> d += 1.2
>>> d
NotImplemented
>>> Why this happens? Really don't know, it's beyond my actual Regarding problem 2: I'll fix that. |
Logged In: YES Hi Facundo, the problem you are seeing seems to be in the way new-style Apparently some part in the (not so new-style anymore) The NotImplemented singleton should never make it to the |
Logged In: YES See proposed patch: bpo-1390657 |
Logged In: YES The patch was committed and fixed this, but only in SVN |
Logged In: YES Backported as r42511. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: