From 72114e3b1aa4758ffc81008457099e9d590505f8 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 28 Sep 2023 14:20:39 +0200 Subject: [PATCH] SettingRelation hash computation improvement CURA-11050 --- UM/Settings/DefinitionContainer.py | 3 +++ UM/Settings/SettingDefinition.py | 2 +- UM/Settings/SettingRelation.py | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/UM/Settings/DefinitionContainer.py b/UM/Settings/DefinitionContainer.py index c1e6440fa6..261cae82c0 100644 --- a/UM/Settings/DefinitionContainer.py +++ b/UM/Settings/DefinitionContainer.py @@ -581,3 +581,6 @@ def __str__(self) -> str: def __repr__(self) -> str: return str(self) + + def __hash__(self) -> int: + return hash(self.getId()) diff --git a/UM/Settings/SettingDefinition.py b/UM/Settings/SettingDefinition.py index 69458b919e..555f24ea2d 100644 --- a/UM/Settings/SettingDefinition.py +++ b/UM/Settings/SettingDefinition.py @@ -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. diff --git a/UM/Settings/SettingRelation.py b/UM/Settings/SettingRelation.py index e6e1a579da..a574ffd74f 100644 --- a/UM/Settings/SettingRelation.py +++ b/UM/Settings/SettingRelation.py @@ -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: