pyblish-base icon indicating copy to clipboard operation
pyblish-base copied to clipboard

Hash for AbstractEntity

Open 2-REC opened this issue 3 years ago • 0 comments

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.

2-REC avatar Feb 09 '22 05:02 2-REC