Skip to content

Commit

Permalink
add type checking for graph __eq__ (#2531)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvora-h authored Jan 8, 2023
1 parent decd1f6 commit c7600b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions redis/commands/graph/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def __str__(self):
return res

def __eq__(self, rhs):
# Type checking
if not isinstance(rhs, Edge):
return False

# Quick positive check, if both IDs are set.
if self.id is not None and rhs.id is not None and self.id == rhs.id:
return True
Expand Down
4 changes: 4 additions & 0 deletions redis/commands/graph/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def __str__(self):
return res

def __eq__(self, rhs):
# Type checking
if not isinstance(rhs, Node):
return False

# Quick positive check, if both IDs are set.
if self.id is not None and rhs.id is not None and self.id != rhs.id:
return False
Expand Down
4 changes: 4 additions & 0 deletions redis/commands/graph/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def add_edge(self, edge):
return self

def __eq__(self, other):
# Type checking
if not isinstance(other, Path):
return False

return self.nodes() == other.nodes() and self.edges() == other.edges()

def __str__(self):
Expand Down

0 comments on commit c7600b4

Please sign in to comment.