Skip to content
Snippets Groups Projects

#187: Implement __eq__ and __hash__ Documents methods

Merged #187: Implement __eq__ and __hash__ Documents methods
12 files
+ 344
10
Compare changes
  • Side-by-side
  • Inline

Files

@@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
from typing import Optional, Type, TypeVar, Union
from typing import Any, Optional, Type, TypeVar, Union
from ..constants import (
BLOCK_ID_REGEX,
@@ -80,6 +80,31 @@ class Certification(Document):
if signing_key is not None:
self.sign(signing_key)
def __eq__(self, other: Any) -> bool:
"""
Check Certification instances equality
"""
if not isinstance(other, Certification):
return NotImplemented
return (
super().__eq__(other)
and self.pubkey_from == other.pubkey_from
and self.identity == other.identity
and self.block_id == other.block_id
)
def __hash__(self) -> int:
return hash(
(
self.pubkey_from,
self.identity,
self.block_id,
self.version,
self.currency,
self.signature,
)
)
@classmethod
def from_signed_raw(
cls: Type[CertificationType], signed_raw: str
Loading