typed_python
typed_python copied to clipboard
Our hash function for floats that are ints doesn't match python
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}.
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
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 .
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.