pyblish-base
pyblish-base copied to clipboard
Hash for AbstractEntity
Feature request
Goal
Allow to compare "AbstractEntity" objects directly, without the need to access the "id" property.
Motivation
When building a list containing several "AbstractEntity" objects (of derived types "Instance" or "Context"), in order to check if an element is already in the list it is currently required to explicitly compare the "id" property of each object. The common "in" operator cannot be used as the objects are not hashable:
if instance in list: # raises an exception
...
Suggested implementation
Add the definition of the "hash" and "eq" functions to the "AbstractEntity" class. In both function, the "id" property is used to determine equality.