@@ -53,21 +53,27 @@ def __init__(
5353 self .owner = owner
5454 self .external_references = external_references or [] # type:ignore[assignment]
5555
56+ @staticmethod
57+ def __comparable_tuple (o : 'Standard' ) -> _ComparableTuple :
58+ return _ComparableTuple ((
59+ o .bom_ref ,
60+ o .name , o .version ,
61+ o .description , o .owner ,
62+ _ComparableTuple (o .external_references )
63+ ))
64+
5665 def __lt__ (self , other : Any ) -> bool :
5766 if isinstance (other , Standard ):
58- return (_ComparableTuple ((self .bom_ref , self .name , self .version ))
59- < _ComparableTuple ((other .bom_ref , other .name , other .version )))
67+ return self .__comparable_tuple (self ) < self .__comparable_tuple (other )
6068 return NotImplemented
6169
6270 def __eq__ (self , other : object ) -> bool :
6371 if isinstance (other , Standard ):
64- return hash ( other ) == hash ( self )
72+ return self . __comparable_tuple ( self ) == self . __comparable_tuple ( other )
6573 return False
6674
6775 def __hash__ (self ) -> int :
68- return hash ((
69- self .bom_ref , self .name , self .version , self .description , self .owner , tuple (self .external_references )
70- ))
76+ return hash (self .__comparable_tuple (self ))
7177
7278 def __repr__ (self ) -> str :
7379 return f'<Standard bom-ref={ self .bom_ref } , name={ self .name } , version={ self .version } , ' \
@@ -212,20 +218,22 @@ def standards(self, standards: Iterable[Standard]) -> None:
212218 def __bool__ (self ) -> bool :
213219 return len (self ._standards ) > 0
214220
215- def __eq__ (self , other : object ) -> bool :
216- if not isinstance (other , Definitions ):
217- return False
218-
219- return self ._standards == other ._standards
221+ @staticmethod
222+ def __comparable_tuple (o : 'Definitions' ) -> _ComparableTuple :
223+ return _ComparableTuple (o ._standards )
220224
221- def __hash__ (self ) -> int :
222- return hash ((tuple (self ._standards )))
225+ def __eq__ (self , other : object ) -> bool :
226+ if isinstance (other , Definitions ):
227+ return self .__comparable_tuple (self ) == self .__comparable_tuple (other )
228+ return False
223229
224230 def __lt__ (self , other : Any ) -> bool :
225231 if isinstance (other , Definitions ):
226- return (_ComparableTuple (self ._standards )
227- < _ComparableTuple (other .standards ))
232+ return self .__comparable_tuple (self ) < self .__comparable_tuple (other )
228233 return NotImplemented
229234
235+ def __hash__ (self ) -> int :
236+ return hash (self .__comparable_tuple (self ))
237+
230238 def __repr__ (self ) -> str :
231239 return '<Definitions>'
0 commit comments