Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

add condition to prevent comparing Example with non-Example object

Tung Dange848b773cb5f
diff --git a/dspy/primitives/example.py b/dspy/primitives/example.py
index 55b06ad8d..5165a442f 100644
--- a/dspy/primitives/example.py
+++ b/dspy/primitives/example.py
@@ -54,7 +54,7 @@ class Example:
return self.__repr__()
def __eq__(self, other):
- return self._store == other._store
+ return isinstance(other, Example) and self._store == other._store
def __hash__(self):
return hash(tuple(self._store.items()))
diff --git a/tests/primitives/test_example.py b/tests/primitives/test_example.py
index 2f27996a2..8900f564a 100644
--- a/tests/primitives/test_example.py
+++ b/tests/primitives/test_example.py
@@ -59,6 +59,7 @@ def test_example_eq():
example1 = Example(a=1, b=2)
example2 = Example(a=1, b=2)
assert example1 == example2
+ assert example1 != ""
def test_example_hash():