From 8c5a2893d6284a9728380731a261a48cc07e2e32 Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Tue, 11 Apr 2023 09:49:07 +0200 Subject: [PATCH] __eq__ operators --- phasmplatform/common/method.py | 8 +++++++- phasmplatform/common/valuetype.py | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/phasmplatform/common/method.py b/phasmplatform/common/method.py index de2d198..8d4bbc8 100644 --- a/phasmplatform/common/method.py +++ b/phasmplatform/common/method.py @@ -1,4 +1,4 @@ -from typing import List +from typing import Any, List from .valuetype import ValueType @@ -14,6 +14,12 @@ class MethodArgument: self.name = name self.value_type = value_type + def __eq__(self, other: Any) -> bool: + if not isinstance(other, MethodArgument): + raise NotImplementedError + + return self.name == other.name and self.value_type == other.value_type + class Method: __slots__ = ('name', 'args', 'return_type', ) diff --git a/phasmplatform/common/valuetype.py b/phasmplatform/common/valuetype.py index 8d01684..36f544e 100644 --- a/phasmplatform/common/valuetype.py +++ b/phasmplatform/common/valuetype.py @@ -1,3 +1,6 @@ +from typing import Any + + class ValueType: __slots__ = ('name', ) @@ -6,6 +9,12 @@ class ValueType: def __init__(self, name: str) -> None: self.name = name + def __eq__(self, other: Any) -> bool: + if not isinstance(other, ValueType): + raise NotImplementedError + + return self is other + bytes = ValueType('bytes')