Add an __eq__ method to Identity

This commit is contained in:
2022-05-04 13:52:20 +02:00
parent 476e6ad22d
commit 1d40bbebc5
2 changed files with 42 additions and 0 deletions

View File

@@ -58,6 +58,17 @@ class Identity:
def __repr__(self) -> str:
return f'<Identity {self}>'
def __eq__(self, other: object) -> bool:
if isinstance(other, str):
return str(self) == other
if isinstance(other, Identity):
return str(self) == str(other)
raise TypeError(
'Dont know how to compare {self.__class__.__name__} and {other.__class__.__name__}'
)
@classmethod
def from_address(cls, address: str) -> 'Identity':
"""Load an identity from an author address"""