pyblish / pyblish-base

Pyblish base library - see https://github.com/pyblish/pyblish for details.
Other
127 stars 59 forks source link

Hash for AbstractEntity #387

Open 2-REC opened 2 years ago

2-REC commented 2 years ago

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.