-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
_decimal difference with _pydecimal #73720
Comments
A difference in behavior between _decimal and _pydecimal (it seems that _decimal is more consistent in this case): class X(Decimal):
def __init__(self, a):
print('__init__:', a)
X.from_float(42.5) # __init__: Decimal('42.5')
X.from_float(42) # with _pydecimal: __init__: 42
# with _decimal: __init__: Decimal('42') |
I get the the same output, perhaps I misunderstand something here: >>> from _decimal import *
>>> class X(Decimal):
... def __init__(self, a):
... print('__init__:', a)
...
>>> X.from_float(42.5)
__init__: 42.5
Decimal('42.5')
>>> X.from_float(42)
__init__: 42
Decimal('42')
>>>
>>>
>>> from _pydecimal import *
>>> class X(Decimal):
... def __init__(self, a):
... print('__init__:', a)
...
>>> X.from_float(42.5)
__init__: 42.5
Decimal('42.5')
>>> X.from_float(42)
__init__: 42
Decimal('42') |
Sorry! It should be repr(a) inside the print. Here is the fixed version: class X(Decimal):
def __init__(self, a):
print('__init__:', repr(a))
X.from_float(42.5) # __init__: Decimal('42.5')
X.from_float(42) # with _pydecimal: __init__: 42
# with _decimal: __init__: Decimal('42') |
I've just added PR for this issue. |
Is there an observable difference in user behaviour if no subclassing of Decimal is involved? Or does this just affect Decimal subclasses? |
BTW, as a user, I'd expect |
actually, it's more related to subclassing, because the problem comes from the fact that before the fix __init__ method receives value as int not Decimal if int passed to from_float call. |
Agree about surprising behaviour but I guess it's better to fix it as other issue because it could break BC in some cases. At least it needs to be investigated. For now I would like to stick with same behaviour for _decimal and _pydecimal |
[Andrew]
No, it's better not to "fix" it at all. :-) It's one of those many behaviour changes where the answer to "Should we have done this differently in the first place" might possibly be "Yes" (and might also be "No"), but the answer to "Should we *change* it now" is a definite "No" (especially given that the "from_float" method is there almost entirely for backwards compatibility). I shouldn't have brought it up. Apologies. |
thanks for your notes, it's absolutely fine and I agree with you :) |
PR merged; thank you! Unfortunately, just after I merged it I noticed that the Misc/NEWS entry was in the wrong section. I'll make a new PR to fix that, and close this issue once it's done. |
All done. Closing. (In theory, as a bugfix, this could be backported to 3.5 and 3.6. In practice, I doubt it's worth the effort.) |
Does anyone know how to disable the spurious pull requests that keep coming in? |
Misc/NEWS
so that it is managed by towncrier #552Note: 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: