[api] refactoring: implementing __eq__ and __hash__ for PackageUpdate

This commit is contained in:
Vinicius Moreira
2022-03-04 11:58:47 -03:00
parent 821fd730a0
commit e737df8e8c
4 changed files with 29 additions and 1 deletions

View File

@@ -263,7 +263,17 @@ class PackageUpdate:
self.type = pkg_type
def __str__(self):
return '{} (id={}, name={}, version={}, type={})'.format(self.__class__.__name__, self.id, self.name, self.version, self.type)
attrs = ', '.join(f'{p}={v}' for p, v in sorted(self.__dict__.items()))
return f'{self.__class__.__name__} ({attrs})'
def __eq__(self, other):
if isinstance(other, PackageUpdate):
return self.__dict__ == other.__dict__
return False
def __hash__(self):
return sum(hash(v) for v in self.__dict__.values())
class PackageHistory: