Skip to content

Commit be56a71

Browse files
authored
add __eq__ and __hash__ for serverless objects (#378)
Co-authored-by: viseshrp <11642379+viseshrp@users.noreply.github.com>
1 parent e90c14c commit be56a71

File tree

1 file changed

+12
-0
lines changed
  • src/ansys/dynamicreporting/core/serverless

1 file changed

+12
-0
lines changed

src/ansys/dynamicreporting/core/serverless/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ def __new__(cls, *args, **kwargs):
157157
)
158158
return super().__new__(cls)
159159

160+
def __eq__(self, other: object) -> bool:
161+
"""Models are equal iff they are the same concrete class and have the same GUID."""
162+
if self is other:
163+
return True
164+
if not isinstance(other, BaseModel):
165+
return NotImplemented
166+
return (self.__class__ is other.__class__) and (self.guid == other.guid)
167+
168+
def __hash__(self) -> int:
169+
"""Hash by concrete class + GUID so instances are usable in sets/dicts."""
170+
return hash((self.__class__, self.guid))
171+
160172
def __repr__(self) -> str:
161173
return f"<{self.__class__.__name__}: {self.guid}>"
162174

0 commit comments

Comments
 (0)