Skip to content

Commit

Permalink
Variable: Implement proper hash
Browse files Browse the repository at this point in the history
The old implementation allowed Variable instances which were equal to
have different hash.
  • Loading branch information
astaric committed Oct 10, 2017
1 parent 01dd07d commit 01f9aec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Orange/data/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ def test_make_proxy_disc(self):
self.assertEqual(abc, abc1)
self.assertEqual(abc, abc2)
self.assertEqual(abc1, abc2)
self.assertEqual(hash(abc), hash(abc1))
self.assertEqual(hash(abc1), hash(abc2))

abcx = DiscreteVariable("abc", values="abc", ordered=True)
self.assertNotEqual(abc, abcx)
Expand All @@ -469,6 +471,8 @@ def test_make_proxy_cont(self):
self.assertEqual(abc, abc1)
self.assertEqual(abc, abc2)
self.assertEqual(abc1, abc2)
self.assertEqual(hash(abc), hash(abc1))
self.assertEqual(hash(abc1), hash(abc2))

def test_proxy_has_separate_colors(self):
abc = ContinuousVariable("abc")
Expand Down
5 changes: 4 additions & 1 deletion Orange/data/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ def __eq__(self, other):
return hasattr(other, "master") and self.master is other.master

def __hash__(self):
return super().__hash__()
if self.master is not self:
return hash(self.master)
else:
return super().__hash__()

@classmethod
def make(cls, name):
Expand Down

0 comments on commit 01f9aec

Please sign in to comment.