Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash for AbstractEntity #387

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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