From 4c30cf3f8e50a0ba45fc35fb35fd90f015981201 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Mon, 15 Apr 2019 21:30:36 +0200 Subject: [PATCH] [feat] InputSource: add equality and hash methods --- duniterpy/documents/transaction.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py index fa950e80..7917c255 100644 --- a/duniterpy/documents/transaction.py +++ b/duniterpy/documents/transaction.py @@ -1,5 +1,5 @@ import re -from typing import TypeVar, List, Type, Optional, Dict, Union +from typing import TypeVar, List, Any, Type, Optional, Dict, Union import pypeg2 @@ -78,6 +78,24 @@ class InputSource: self.origin_id = origin_id self.index = index + + def __eq__(self, other: Any) -> bool: + """ + Check InputSource instances equality + """ + if not isinstance(other, InputSource): + return NotImplemented + return self.amount == other.amount and\ + self.base == other.base and\ + self.source == other.source and\ + self.origin_id == other.origin_id and\ + self.index == other.index + + + def __hash__(self) -> int: + return hash((self.amount, self.base, self.source, self.origin_id, self.index)) + + @classmethod def from_inline(cls: Type[InputSourceType], tx_version: int, inline: str) -> InputSourceType: """ -- GitLab