asmeurer / blog

My blog
https://www.asmeurer.com/blog/
8 stars 2 forks source link

What happens when you mess with hashing in Python | Aaron Meurer's Blog #9

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

What happens when you mess with hashing in Python | Aaron Meurer's Blog

https://asmeurer.com/blog/posts/what-happens-when-you-mess-with-hashing-in-python/

asmeurer commented 3 years ago

To comment on this post, click on "Sign in with GitHub" below. If you don't want to authorize the Utterances bot, you can go to the GitHub issues page for this post and comment there.

asmeurer commented 3 years ago

These are the original comments on this post that were made when this blog used the Disqus blog system.

Comment from bjd2385 on 2016-08-28 12:33:12+00:00:

Very interesting post. I was just looking into hash functions (I've never formally learned what the topic entails), and since I'm most familiar with Python this post explained quite a bit, especially your early mathematical points.

Comment from Mark Lawrence on 2016-10-03 20:26:54+00:00:

At what point does Python 3 force the override of __hash__ if you've defined __eq__? E.g when would your

AlwaysEqual class fail?

Replies:

Comment from asmeurer on 2016-10-03 20:38:13+00:00:

That's a good catch. I originally wrote this post in Python 2. The example does indeed fail in Python 3. More specifically, if you override __eq__, Python 3 automatically sets __hash__ to None. I'll update the post to make this more clear.

Comment from Erick Mendonça on 2017-07-30 03:23:55+00:00:

Great article! We must really pay attention to these details when implementing custom hashes.

Comment from Ignacio on 2017-10-07 22:31:56+00:00:

Thanks a lot for this post! Clarified a lot of concepts.