Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node comparison: == on nodes now checks contents #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions redbaron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -586,6 +594,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())
Expand Down