@@ -53,21 +53,27 @@ def __init__(
53
53
self .owner = owner
54
54
self .external_references = external_references or [] # type:ignore[assignment]
55
55
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
+
56
65
def __lt__ (self , other : Any ) -> bool :
57
66
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 )
60
68
return NotImplemented
61
69
62
70
def __eq__ (self , other : object ) -> bool :
63
71
if isinstance (other , Standard ):
64
- return hash ( other ) == hash ( self )
72
+ return self . __comparable_tuple ( self ) == self . __comparable_tuple ( other )
65
73
return False
66
74
67
75
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 ))
71
77
72
78
def __repr__ (self ) -> str :
73
79
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:
212
218
def __bool__ (self ) -> bool :
213
219
return len (self ._standards ) > 0
214
220
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 )
220
224
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
223
229
224
230
def __lt__ (self , other : Any ) -> bool :
225
231
if isinstance (other , Definitions ):
226
- return (_ComparableTuple (self ._standards )
227
- < _ComparableTuple (other .standards ))
232
+ return self .__comparable_tuple (self ) < self .__comparable_tuple (other )
228
233
return NotImplemented
229
234
235
+ def __hash__ (self ) -> int :
236
+ return hash (self .__comparable_tuple (self ))
237
+
230
238
def __repr__ (self ) -> str :
231
239
return '<Definitions>'
0 commit comments