@@ -115,31 +115,28 @@ def __init__(
115115 self .properties = properties or () # type:ignore[assignment]
116116 self .external_references = external_references or () # type:ignore[assignment]
117117
118+ def __comparable_tuple (self ) -> _ComparableTuple :
119+ # all properties are optional - so need to compare all, in hope that one is unique
120+ return _ComparableTuple ((
121+ self .bom_ref , self .identifier ,
122+ self .title , self .text ,
123+ _ComparableTuple (self .descriptions ),
124+ _ComparableTuple (self .open_cre ), self .parent , _ComparableTuple (self .properties ),
125+ _ComparableTuple (self .external_references )
126+ ))
127+
118128 def __lt__ (self , other : Any ) -> bool :
119129 if isinstance (other , Requirement ):
120- # all properties are optional - so need to compare all, in hope that one is unique
121- return _ComparableTuple ((
122- self .bom_ref , self .identifier , self .title , self .text , _ComparableTuple (self .descriptions ),
123- _ComparableTuple (self .open_cre ), self .parent , _ComparableTuple (self .properties ),
124- _ComparableTuple (self .external_references )
125- )) < _ComparableTuple ((
126- other .bom_ref , other .identifier , other .title , other .text , _ComparableTuple (other .descriptions ),
127- _ComparableTuple (other .open_cre ), other .parent , _ComparableTuple (other .properties ),
128- _ComparableTuple (other .external_references )
129- ))
130+ return self .__comparable_tuple () < other .__comparable_tuple ()
130131 return NotImplemented
131132
132133 def __eq__ (self , other : object ) -> bool :
133134 if isinstance (other , Requirement ):
134- return hash ( other ) == hash ( self )
135+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
135136 return False
136137
137138 def __hash__ (self ) -> int :
138- # all properties are optional - so need to apply all, in hope that one is unique
139- return hash ((
140- self .bom_ref , self .identifier , self .title , self .text , tuple (self .descriptions ),
141- tuple (self .open_cre ), self .parent , tuple (self .properties ), tuple (self .external_references )
142- ))
139+ return hash (self .__comparable_tuple ())
143140
144141 def __repr__ (self ) -> str :
145142 return f'<Requirement bom-ref={ self ._bom_ref } , identifier={ self .identifier } , title={ self .title } , ' \
@@ -246,7 +243,7 @@ def parent(self) -> Optional[BomRef]:
246243
247244 @parent .setter
248245 def parent (self , parent : Optional [Union [str , BomRef ]]) -> None :
249- self ._parent = _bom_ref_from_str (parent )
246+ self ._parent = _bom_ref_from_str (parent , optional = True )
250247
251248 @property
252249 @serializable .xml_array (serializable .XmlArraySerializationType .NESTED , 'property' )
@@ -303,26 +300,24 @@ def __init__(
303300 self .description = description
304301 self .requirements = requirements or () # type:ignore[assignment]
305302
303+ def __comparable_tuple (self ) -> _ComparableTuple :
304+ # all properties are optional - so need to compare all, in hope that one is unique
305+ return _ComparableTuple ((
306+ self .bom_ref , self .identifier , self .title , self .description , _ComparableTuple (self .requirements )
307+ ))
308+
306309 def __lt__ (self , other : Any ) -> bool :
307310 if isinstance (other , Level ):
308- # all properties are optional - so need to compare all, in hope that one is unique
309- return _ComparableTuple ((
310- self .bom_ref , self .identifier , self .title , self .description , _ComparableTuple (self .requirements )
311- )) < _ComparableTuple ((
312- other .bom_ref , other .identifier , other .title , other .description , _ComparableTuple (other .requirements )
313- ))
311+ return self .__comparable_tuple () < other .__comparable_tuple ()
314312 return NotImplemented
315313
316314 def __eq__ (self , other : object ) -> bool :
317315 if isinstance (other , Level ):
318- return hash ( other ) == hash ( self )
316+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
319317 return False
320318
321319 def __hash__ (self ) -> int :
322- # all properties are optional - so need to compare all, in hope that one is unique
323- return hash ((
324- self .bom_ref , self .identifier , self .title , self .description , tuple (self .requirements )
325- ))
320+ return hash (self .__comparable_tuple ())
326321
327322 def __repr__ (self ) -> str :
328323 return f'<Level bom-ref={ self .bom_ref } , identifier={ self .identifier } , title={ self .title } , ' \
@@ -424,31 +419,27 @@ def __init__(
424419 self .levels = levels or () # type:ignore[assignment]
425420 self .external_references = external_references or () # type:ignore[assignment]
426421
422+ def __comparable_tuple (self ) -> _ComparableTuple :
423+ # all properties are optional - so need to apply all, in hope that one is unique
424+ return _ComparableTuple ((
425+ self .bom_ref ,
426+ self .name , self .version , self .description , self .owner ,
427+ _ComparableTuple (self .requirements ), _ComparableTuple (self .levels ),
428+ _ComparableTuple (self .external_references )
429+ ))
430+
427431 def __lt__ (self , other : Any ) -> bool :
428432 if isinstance (other , Standard ):
429- # all properties are optional - so need to apply all, in hope that one is unique
430- return _ComparableTuple ((
431- self .bom_ref , self .name , self .version , self .description , self .owner ,
432- _ComparableTuple (self .requirements ), _ComparableTuple (self .levels ),
433- _ComparableTuple (self .external_references )
434- )) < _ComparableTuple ((
435- self .bom_ref , self .name , self .version , self .description , self .owner ,
436- _ComparableTuple (self .requirements ), _ComparableTuple (self .levels ),
437- _ComparableTuple (self .external_references )
438- ))
433+ return self .__comparable_tuple () < other .__comparable_tuple ()
439434 return NotImplemented
440435
441436 def __eq__ (self , other : object ) -> bool :
442437 if isinstance (other , Standard ):
443- return hash ( other ) == hash ( self )
438+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
444439 return False
445440
446441 def __hash__ (self ) -> int :
447- # all properties are optional - so need to apply all, in hope that one is unique
448- return hash ((
449- self .bom_ref , self .name , self .version , self .description , self .owner ,
450- tuple (self .requirements ), tuple (self .levels ), tuple (self .external_references )
451- ))
442+ return hash (self .__comparable_tuple ())
452443
453444 def __repr__ (self ) -> str :
454445 return f'<Standard bom-ref={ self .bom_ref } , name={ self .name } , version={ self .version } , ' \
@@ -593,19 +584,21 @@ def standards(self, standards: Iterable[Standard]) -> None:
593584 def __bool__ (self ) -> bool :
594585 return len (self ._standards ) > 0
595586
587+ def __comparable_tuple (self ) -> _ComparableTuple :
588+ # all properties are optional - so need to apply all, in hope that one is unique
589+ return _ComparableTuple (self ._standards )
590+
596591 def __eq__ (self , other : object ) -> bool :
597592 if isinstance (other , Definitions ):
598- return hash ( self ) == hash ( other )
593+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
599594 return False
600595
601596 def __hash__ (self ) -> int :
602- # all properties are optional - so need to apply all, in hope that one is unique
603- return hash (tuple (self ._standards ))
597+ return hash (self .__comparable_tuple ())
604598
605599 def __lt__ (self , other : Any ) -> bool :
606600 if isinstance (other , Definitions ):
607- # all properties are optional - so need to apply all, in hope that one is unique
608- return _ComparableTuple (self ._standards ) < _ComparableTuple (other ._standards )
601+ return self .__comparable_tuple () < other .__comparable_tuple ()
609602 return NotImplemented
610603
611604 def __repr__ (self ) -> str :
0 commit comments