@@ -171,22 +171,23 @@ def message(self) -> Optional[str]:
171171 def message (self , message : Optional [str ]) -> None :
172172 self ._message = message
173173
174+ def __comparable_tuple (self ) -> _ComparableTuple :
175+ return _ComparableTuple ((
176+ self .uid , self .url , self .author , self .committer , self .message
177+ ))
178+
174179 def __eq__ (self , other : object ) -> bool :
175180 if isinstance (other , Commit ):
176- return hash ( other ) == hash ( self )
181+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
177182 return False
178183
179184 def __lt__ (self , other : Any ) -> bool :
180185 if isinstance (other , Commit ):
181- return _ComparableTuple ((
182- self .uid , self .url , self .author , self .committer , self .message
183- )) < _ComparableTuple ((
184- other .uid , other .url , other .author , other .committer , other .message
185- ))
186+ return self .__comparable_tuple () < other .__comparable_tuple ()
186187 return NotImplemented
187188
188189 def __hash__ (self ) -> int :
189- return hash (( self .uid , self . url , self . author , self . committer , self . message ))
190+ return hash (self .__comparable_tuple ( ))
190191
191192 def __repr__ (self ) -> str :
192193 return f'<Commit uid={ self .uid } , url={ self .url } , message={ self .message } >'
@@ -281,13 +282,19 @@ def copyright(self) -> 'SortedSet[Copyright]':
281282 def copyright (self , copyright : Iterable [Copyright ]) -> None :
282283 self ._copyright = SortedSet (copyright )
283284
285+ def __comparable_tuple (self ) -> _ComparableTuple :
286+ return _ComparableTuple ((
287+ _ComparableTuple (self .licenses ),
288+ _ComparableTuple (self .copyright ),
289+ ))
290+
284291 def __eq__ (self , other : object ) -> bool :
285292 if isinstance (other , ComponentEvidence ):
286- return hash ( other ) == hash ( self )
293+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
287294 return False
288295
289296 def __hash__ (self ) -> int :
290- return hash (( tuple ( self .licenses ), tuple ( self . copyright ) ))
297+ return hash (self .__comparable_tuple ( ))
291298
292299 def __repr__ (self ) -> str :
293300 return f'<ComponentEvidence id={ id (self )} >'
@@ -478,22 +485,23 @@ def url(self) -> Optional[XsUri]:
478485 def url (self , url : Optional [XsUri ]) -> None :
479486 self ._url = url
480487
488+ def __comparable_tuple (self ) -> _ComparableTuple :
489+ return _ComparableTuple ((
490+ self .text , self .url
491+ ))
492+
481493 def __eq__ (self , other : object ) -> bool :
482494 if isinstance (other , Diff ):
483- return hash ( other ) == hash ( self )
495+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
484496 return False
485497
486498 def __lt__ (self , other : Any ) -> bool :
487499 if isinstance (other , Diff ):
488- return _ComparableTuple ((
489- self .url , self .text
490- )) < _ComparableTuple ((
491- other .url , other .text
492- ))
500+ return self .__comparable_tuple () < other .__comparable_tuple ()
493501 return NotImplemented
494502
495503 def __hash__ (self ) -> int :
496- return hash (( self .text , self . url ))
504+ return hash (self .__comparable_tuple ( ))
497505
498506 def __repr__ (self ) -> str :
499507 return f'<Diff url={ self .url } >'
@@ -580,22 +588,23 @@ def resolves(self) -> 'SortedSet[IssueType]':
580588 def resolves (self , resolves : Iterable [IssueType ]) -> None :
581589 self ._resolves = SortedSet (resolves )
582590
591+ def __comparable_tuple (self ) -> _ComparableTuple :
592+ return _ComparableTuple ((
593+ self .type , self .diff , _ComparableTuple (self .resolves )
594+ ))
595+
583596 def __eq__ (self , other : object ) -> bool :
584597 if isinstance (other , Patch ):
585- return hash ( other ) == hash ( self )
598+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
586599 return False
587600
588601 def __lt__ (self , other : Any ) -> bool :
589602 if isinstance (other , Patch ):
590- return _ComparableTuple ((
591- self .type , self .diff , _ComparableTuple (self .resolves )
592- )) < _ComparableTuple ((
593- other .type , other .diff , _ComparableTuple (other .resolves )
594- ))
603+ return self .__comparable_tuple () < other .__comparable_tuple ()
595604 return NotImplemented
596605
597606 def __hash__ (self ) -> int :
598- return hash (( self .type , self . diff , tuple ( self . resolves ) ))
607+ return hash (self .__comparable_tuple ( ))
599608
600609 def __repr__ (self ) -> str :
601610 return f'<Patch type={ self .type } , id={ id (self )} >'
@@ -1741,52 +1750,33 @@ def get_pypi_url(self) -> str:
17411750 else :
17421751 return f'https://pypi.org/project/{ self .name } '
17431752
1753+ def __comparable_tuple (self ) -> _ComparableTuple :
1754+ return _ComparableTuple ((
1755+ self .type , self .group , self .name , self .version ,
1756+ self .mime_type , self .supplier , self .author , self .publisher ,
1757+ self .description , self .scope , _ComparableTuple (self .hashes ),
1758+ _ComparableTuple (self .licenses ), self .copyright , self .cpe ,
1759+ None if self .purl is None else _ComparablePackageURL (self .purl ),
1760+ self .swid , self .pedigree ,
1761+ _ComparableTuple (self .external_references ), _ComparableTuple (self .properties ),
1762+ _ComparableTuple (self .components ), self .evidence , self .release_notes , self .modified ,
1763+ _ComparableTuple (self .authors ), _ComparableTuple (self .omnibor_ids ), self .manufacturer ,
1764+ _ComparableTuple (self .swhids ), self .crypto_properties , _ComparableTuple (self .tags ),
1765+ ))
1766+
17441767 def __eq__ (self , other : object ) -> bool :
17451768 if isinstance (other , Component ):
1746- return hash ( other ) == hash ( self )
1769+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
17471770 return False
17481771
17491772 def __lt__ (self , other : Any ) -> bool :
17501773 if isinstance (other , Component ):
1751- return _ComparableTuple ((
1752- self .type , self .group , self .name , self .version ,
1753- self .mime_type , self .supplier , self .author , self .publisher ,
1754- self .description , self .scope , _ComparableTuple (self .hashes ),
1755- _ComparableTuple (self .licenses ), self .copyright , self .cpe ,
1756- None if self .purl is None else _ComparablePackageURL (self .purl ),
1757- self .swid , self .pedigree ,
1758- _ComparableTuple (self .external_references ), _ComparableTuple (self .properties ),
1759- _ComparableTuple (self .components ), self .evidence , self .release_notes , self .modified ,
1760- _ComparableTuple (self .authors ), _ComparableTuple (self .omnibor_ids ), self .manufacturer ,
1761- _ComparableTuple (self .swhids ), self .crypto_properties , _ComparableTuple (self .tags )
1762- )) < _ComparableTuple ((
1763- other .type , other .group , other .name , other .version ,
1764- other .mime_type , other .supplier , other .author , other .publisher ,
1765- other .description , other .scope , _ComparableTuple (other .hashes ),
1766- _ComparableTuple (other .licenses ), other .copyright , other .cpe ,
1767- None if other .purl is None else _ComparablePackageURL (other .purl ),
1768- other .swid , other .pedigree ,
1769- _ComparableTuple (other .external_references ), _ComparableTuple (other .properties ),
1770- _ComparableTuple (other .components ), other .evidence , other .release_notes , other .modified ,
1771- _ComparableTuple (other .authors ), _ComparableTuple (other .omnibor_ids ), other .manufacturer ,
1772- _ComparableTuple (other .swhids ), other .crypto_properties , _ComparableTuple (other .tags )
1773- ))
1774+ return self .__comparable_tuple () < other .__comparable_tuple ()
17741775 return NotImplemented
17751776
17761777 def __hash__ (self ) -> int :
1777- return hash ((
1778- self .type , self .group , self .name , self .version ,
1779- self .mime_type , self .supplier , self .author , self .publisher ,
1780- self .description , self .scope , tuple (self .hashes ),
1781- tuple (self .licenses ), self .copyright , self .cpe ,
1782- self .purl ,
1783- self .swid , self .pedigree ,
1784- tuple (self .external_references ), tuple (self .properties ),
1785- tuple (self .components ), self .evidence , self .release_notes , self .modified ,
1786- tuple (self .authors ), tuple (self .omnibor_ids ), self .manufacturer ,
1787- tuple (self .swhids ), self .crypto_properties , tuple (self .tags )
1788- ))
1778+ return hash (self .__comparable_tuple ())
17891779
17901780 def __repr__ (self ) -> str :
17911781 return f'<Component bom-ref={ self .bom_ref !r} , group={ self .group } , name={ self .name } , ' \
1792- f'version={ self .version } , type={ self .type } >'
1782+ f'version={ self .version } , type={ self .type } >'
0 commit comments