dcreager.net

The __hash__ method can be removed

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:

__hash__, __eq__, and LSP [Python Discourse]

» Languages » Python