From 90d60f2f1aaa735ed9ba5c8737906171fe9d2323 Mon Sep 17 00:00:00 2001 From: "Adrien \"ze\" Urban" Date: Tue, 17 Jun 2014 22:40:03 +0200 Subject: [PATCH 1/2] Node comparison: == on nodes now checks contents Same as comparing fst, but without building each explicitly first --- redbaron.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/redbaron.py b/redbaron.py index 1fcd9dfb..bbf07b06 100644 --- a/redbaron.py +++ b/redbaron.py @@ -586,6 +586,15 @@ def __repr__(self): else: return self.dumps() + def __eq__(self, other): + return not self != other + + def __ne__(self, other): + for key in itertools.chain(self._str_keys, self._list_keys, self._dict_keys): + if getattr(self, key) != getattr(other, key, None): + return True + return False + def copy(self): # XXX not very optimised but at least very simple return to_node(self.fst()) From bf485a3a414f0f930fefa236a3ce92cf75c62686 Mon Sep 17 00:00:00 2001 From: "Adrien \"ze\" Urban" Date: Wed, 18 Jun 2014 10:34:14 +0200 Subject: [PATCH 2/2] Path comparison: implement == on Path --- redbaron.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/redbaron.py b/redbaron.py index bbf07b06..138dc416 100644 --- a/redbaron.py +++ b/redbaron.py @@ -71,6 +71,14 @@ def set_node(self, node): self.path = baron.path.make_path(path, parent_node_type, render_pos) + def __eq__(self, other): + return not self != other + + def __ne__(self, other): + if not isinstance(other, Path): + return True + return self.path != other.path + @classmethod def from_baron_path(class_, node, path): if baron.path.is_empty(path):