This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients Radosław Szalski, mark.dickinson
Date 2016-06-09.17:54:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1465494873.23.0.58399102275.issue27265@psf.upfronthosting.co.za>
In-reply-to
Content
> the behavior differs simply based on whether the Decimal was created from a string vs a float

That's not quite right: a Decimal object keeps no knowledge of how it was created. The behaviour differs depending on whether the value of the Decimal happens to be exactly representable as a Python float or not. That's necessary to ensure the invariant `x == y` implies `hash(x) == hash(y)` continues to hold across types (though Python 3 has a better way of doing this).

So for example `Decimal('0.375')` was created from a string, but will hash equal to the exactly equal float `0.375`:

noether:float-proofs mdickinson$ python2
Python 2.7.11 (default, May  1 2016, 08:20:00) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> hash(Decimal('0.375')), hash(Decimal(0.375))
(1610579968, 1610579968)
>>> hash(0.375)
1610579968
History
Date User Action Args
2016-06-09 17:54:33mark.dickinsonsetrecipients: + mark.dickinson, Radosław Szalski
2016-06-09 17:54:33mark.dickinsonsetmessageid: <1465494873.23.0.58399102275.issue27265@psf.upfronthosting.co.za>
2016-06-09 17:54:33mark.dickinsonlinkissue27265 messages
2016-06-09 17:54:32mark.dickinsoncreate