Skip to content

Commit

Permalink
SettingRelation hash computation improvement
Browse files Browse the repository at this point in the history
CURA-11050
  • Loading branch information
wawanbreton committed Sep 28, 2023
1 parent 02ea31d commit 72114e3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions UM/Settings/DefinitionContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,6 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return str(self)

def __hash__(self) -> int:
return hash(self.getId())
2 changes: 1 addition & 1 deletion UM/Settings/SettingDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __setattr__(self, name: str, value: Any) -> None:
def __hash__(self):
"""Ensure that the SettingDefinition is hashable, so it can be used in a set."""

return hash(str(self))
return hash((id(self), self._key, self._container))

def __getstate__(self):
"""For Pickle support.
Expand Down
4 changes: 2 additions & 2 deletions UM/Settings/SettingRelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __init__(self, owner: SettingDefinition, target: SettingDefinition, relation
self._type = relation_type
self._role = role

def __hash__(self):
def __hash__(self) -> int:
"""Ensure that the SettingRelation is hashable, so it can be used in a set."""

return hash(str(self))
return hash((self._owner, self._target, self._type, self._role))

@property
def owner(self) -> SettingDefinition:
Expand Down

0 comments on commit 72114e3

Please sign in to comment.