Skip to content

Commit cf3d0d8

Browse files
committed
Implemented __hash__ and __eq__ for Q objects, closing issue #5.
1 parent e1de334 commit cf3d0d8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lucenequerybuilder/query.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ def __add__(self, other):
108108
def __sub__(self, other):
109109
return self | Q._make_must_not(self)
110110

111+
def __eq__(self, other):
112+
return hash(self) == hash(other)
113+
114+
def __hash__(self):
115+
return hash((tuple(self.should), tuple(self.must), tuple(self.must_not)))
116+
111117
def __str__(self):
112118
rv = ''
113119
if hasattr(self, 'field'):

lucenequerybuilder/tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def test_hashing():
5151
d[q2] = 2
5252
except:
5353
raise AssertionError('There was an error using queries as dict keys.')
54-
assert d[q1] == 1, 'Got the wrong value back from the query dict!'
5554
assert d[q2] == 2, 'Got the wrong value back from the query dict!'
5655

5756

0 commit comments

Comments
 (0)