@@ -254,23 +254,23 @@ def phone(self) -> Optional[str]:
254254 def phone (self , phone : Optional [str ]) -> None :
255255 self ._phone = phone
256256
257+ def __comparable_tuple (self ) -> _ComparableTuple :
258+ return _ComparableTuple ((
259+ self .name , self .email , self .phone
260+ ))
261+
257262 def __eq__ (self , other : object ) -> bool :
258263 if isinstance (other , OrganizationalContact ):
259- return hash ( other ) == hash ( self )
264+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
260265 return False
261266
262267 def __lt__ (self , other : Any ) -> bool :
263268 if isinstance (other , OrganizationalContact ):
264- return _ComparableTuple ((
265- self .name , self .email , self .phone
266- )) < _ComparableTuple ((
267- other .name , other .email , other .phone
268- ))
269+ return self .__comparable_tuple () < other .__comparable_tuple ()
269270 return NotImplemented
270271
271272 def __hash__ (self ) -> int :
272- # TODO
273- return hash ((self .name , self .phone , self .email ))
273+ return hash (self .__comparable_tuple ())
274274
275275 def __repr__ (self ) -> str :
276276 return f'<OrganizationalContact name={ self .name } , email={ self .email } , phone={ self .phone } >'
@@ -364,19 +364,23 @@ def contacts(self) -> 'SortedSet[OrganizationalContact]':
364364 def contacts (self , contacts : Iterable [OrganizationalContact ]) -> None :
365365 self ._contacts = SortedSet (contacts )
366366
367+ def __comparable_tuple (self ) -> _ComparableTuple :
368+ return _ComparableTuple ((
369+ self .name , _ComparableTuple (self .urls ), _ComparableTuple (self .contacts )
370+ ))
371+
367372 def __eq__ (self , other : object ) -> bool :
368373 if isinstance (other , OrganizationalEntity ):
369- return hash ( other ) == hash ( self )
374+ return self . __comparable_tuple ( ) == other . __comparable_tuple ( )
370375 return False
371376
372377 def __lt__ (self , other : Any ) -> bool :
373378 if isinstance (other , OrganizationalEntity ):
374- return hash ( self ) < hash ( other )
379+ return self . __comparable_tuple ( ) < other . __comparable_tuple ( )
375380 return NotImplemented
376381
377382 def __hash__ (self ) -> int :
378- # TODO
379- return hash ((self .name , tuple (self .urls ), tuple (self .contacts )))
383+ return hash (self .__comparable_tuple ())
380384
381385 def __repr__ (self ) -> str :
382386 return f'<OrganizationalEntity name={ self .name } >'
0 commit comments