Fix Python – How can I make a python dataclass hashable?

Say a I have a dataclass in python3. I want to be able to hash and order these objects.
I only want them ordered/hashed on id.
I see in the docs that I can just implement _hash_ and all that but I’d like to get datacalsses to do the work for me because they are intended to handle this.
from dataclasses import dataclass, field

@dataclass(eq=True, ….

Fix Python – Making a python user-defined class sortable, hashable

What methods need to be overridden/implemented when making user-defined classes sortable and/or hashable in python?
What are the gotchas to watch out for?
I type dir({}) into my interpreter to get a list of methods on built-in dicts. Of those, I assume I need to some implement some subset of
[‘__cmp__’, ‘__eq__’, ‘__ge__’, ‘__gt__’, ‘__hash__’, ‘….

Fix Python – What does hash do in python?

I saw an example of code that where hash function is applied to a tuple. As a result it returns a negative integer. I wonder what does this function do? Google does not help. I found a page that explains how hash is calculated but it does not explain why we need this function.

Fix Python – hash function in Python 3.3 returns different results between sessions

I’ve implemented a BloomFilter in python 3.3, and got different results every session. Drilling down this weird behavior got me to the internal hash() function – it returns different hash values for the same string every session.
>>> hash(“235”)

—– opening a new python console —–
>>> hash(“235”)

Fix Python – Hashing a dictionary?

For caching purposes I need to generate a cache key from GET arguments which are present in a dict.
Currently I’m using sha1(repr(sorted(my_dict.items()))) (sha1() is a convenience method that uses hashlib internally) but I’m curious if there’s a better way.