From 2020d20ee5a3cb8ffa8b9ed10500f7e29b6aa681 Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Thu, 24 Aug 2017 13:50:09 +0200 Subject: [PATCH] Add a default __eq__ method for JsonObject --- jsonobject/api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jsonobject/api.py b/jsonobject/api.py index 641967d..729b3c9 100644 --- a/jsonobject/api.py +++ b/jsonobject/api.py @@ -30,6 +30,13 @@ def __getstate__(self): def __setstate__(self, dct): self.__init__(dct) + def __eq__(self, other: object) -> bool: + if not isinstance(other, JsonObject): + raise TypeError( + "Expected an argument of type JsonObject, got: {}".format(type(other)) + ) + return sorted(self.items()) == sorted(other.items()) + class Meta(object): properties = { decimal.Decimal: properties.DecimalProperty,