Skip to content

Conversation

@2-REC
Copy link

@2-REC 2-REC commented Feb 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant