Skip to content

Commit 1ec6d7d

Browse files
committed
Tweaked Path eq and hash functions
1 parent d6036fa commit 1ec6d7d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

onshape_api/paths/paths.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __hash__(self) -> int:
4848
return hash(self.document_id)
4949

5050
def __eq__(self, other) -> bool:
51-
return isinstance(other, DocumentPath) and self.document_id == other.document_id
51+
return isinstance(other, type(self)) and self.document_id == other.document_id
5252

5353
def __str__(self) -> str:
5454
return DocumentPath.to_api_path(self)
@@ -107,11 +107,11 @@ def copy(cls, instance: InstancePath) -> InstancePath:
107107
return cls(instance.document_id, instance.instance_id, instance.instance_type)
108108

109109
def __hash__(self) -> int:
110-
return super().__hash__() ^ hash(self.instance_id) ^ hash(self.wvm)
110+
return hash((super().__hash__(), self.instance_id, self.wvm))
111111

112112
def __eq__(self, other) -> bool:
113113
return (
114-
isinstance(other, InstancePath)
114+
isinstance(other, type(self))
115115
and super().__eq__(other)
116116
and self.instance_id == other.instance_id
117117
and self.wvm == other.wvm
@@ -163,11 +163,11 @@ def copy(cls, element: ElementPath) -> ElementPath:
163163
)
164164

165165
def __hash__(self) -> int:
166-
return super().__hash__() ^ hash(self.element_id)
166+
return hash((super().__hash__(), self.element_id))
167167

168168
def __eq__(self, other) -> bool:
169169
return (
170-
isinstance(other, ElementPath)
170+
isinstance(other, type(self))
171171
and self.__eq__(other)
172172
and self.element_id == other.element_id
173173
)
@@ -217,11 +217,11 @@ def from_path(cls, element: ElementPath, part_id: str) -> PartPath:
217217
)
218218

219219
def __hash__(self) -> int:
220-
return super().__hash__() ^ hash(self.part_id)
220+
return hash((super().__hash__(), self.part_id))
221221

222222
def __eq__(self, other) -> bool:
223223
return (
224-
isinstance(other, PartPath)
224+
isinstance(other, type(self))
225225
and self.__eq__(other)
226226
and self.part_id == other.part_id
227227
)

0 commit comments

Comments
 (0)