πΎ Archived View for dcreager.net βΊ languages βΊ python βΊ hash-method-removed.gmi captured on 2024-12-17 at 09:33:22. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
If a class implements both β__eq__β and β__hash__β, it's important for those implementations to be consistent with each other:
a == b β hash(a) == hash(b)
TIL that Python will try to help you adhere to this constraint in the presence of subclasses. If you define a subclass, and implement β__eq__β _but not_ β__hash__β, then Python will implicitly set β__hash__β to βNoneβ in that class. That way you can't accidentally override the meaning of βequalsβ in a way that breaks hashability.
βobject.__hash__β documentation
This has some ramifications with the type system: