typed_python icon indicating copy to clipboard operation
typed_python copied to clipboard

Our hash function for floats that are ints doesn't match python

Open braxtonmckee opened this issue 5 years ago • 3 comments

Python has a behavior where hash(1.0) == hash(1) == hash(True) == 1. This happens so that you can look up an int in a dictionary with a float and vice versa (since they also compare equal). We are definitely not matching this behavior, and so (a) we will allow a Dict(OneOf(float, int)) to have separate values for 1.0 and 1, which python does not allow, and (b) we will consider {1:2} to be != {1.0: 2}.

braxtonmckee avatar Jun 30 '19 03:06 braxtonmckee

It looks like there is something else checked too https://stackoverflow.com/questions/114830/is-a-python-dictionary-an-example-of-a-hash-table/33459086#33459086

szymonlipinski avatar Jul 02 '19 18:07 szymonlipinski

yes, python looks in has bucket first, then equality of items using eq.

On Tue, Jul 2, 2019 at 2:22 PM Szymon Lipiński [email protected] wrote:

It looks like there is something else checked too https://stackoverflow.com/questions/114830/is-a-python-dictionary-an-example-of-a-hash-table/33459086#33459086

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/APrioriInvestments/nativepython/issues/142?email_source=notifications&email_token=AB6OHBHGLJ2YICA7SSUKZLTP5OMG7A5CNFSM4H4LU2E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZCETJI#issuecomment-507791781, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6OHBAIJ3Z5HET5QGM6JJTP5OMG7ANCNFSM4H4LU2EQ .

braxtonmckee avatar Jul 02 '19 18:07 braxtonmckee

We should also not be comparing things that are different types like this unless we can actually dispatch to an operator properly. Python won't let you check ("hi",) < (1.0,), (although it'll let you check ==). We should be mimicking that behavior.

braxtonmckee avatar Oct 08 '19 23:10 braxtonmckee