Python

Python

Made by DeepSource

Defining equality for a class without also defining hashability PYL-W1641

Bug risk
Major

In order to conform to the object model, classes that define their own equality method should also define their own hash method, or be unhashable. If the hash method is not defined then the hash of the super class is used. This is unlikely to result in the expected behavior.

A class can be made unhashable by setting its __hash__ attribute to None.

In Python 3, if you define a class-level equality method and omit a __hash__ method then the class is automatically marked as unhashable.

It is recommended to implement a __hash__ method or set __hash__ = None, whenever you define an __eq__ method for a class.