From c7600b4c7e558d3c05485f76cfcdd3e807c6b13e Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Sun, 8 Jan 2023 10:42:19 +0200 Subject: [PATCH] add type checking for graph __eq__ (#2531) --- redis/commands/graph/edge.py | 4 ++++ redis/commands/graph/node.py | 4 ++++ redis/commands/graph/path.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/redis/commands/graph/edge.py b/redis/commands/graph/edge.py index b0141d9452..6ee195f1f5 100644 --- a/redis/commands/graph/edge.py +++ b/redis/commands/graph/edge.py @@ -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 diff --git a/redis/commands/graph/node.py b/redis/commands/graph/node.py index 0ebe510ada..4546a393b1 100644 --- a/redis/commands/graph/node.py +++ b/redis/commands/graph/node.py @@ -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 diff --git a/redis/commands/graph/path.py b/redis/commands/graph/path.py index 6f2214a3b5..ee22dc8c6b 100644 --- a/redis/commands/graph/path.py +++ b/redis/commands/graph/path.py @@ -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):