Skip to content

Commit

Permalink
Make Winner hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
dustalov committed Aug 24, 2024
1 parent b23781c commit cb7e3d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/evalica/test_evalica.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def test_exports() -> None:
assert hasattr(evalica, attr), f"missing attribute: {attr}"


def test_winner_hashable() -> None:
assert len(evalica.WINNERS) == len(set(evalica.WINNERS))


def test_winner_pickle() -> None:
for w in evalica.WINNERS:
dumped = pickle.dumps(w)
Expand Down
5 changes: 5 additions & 0 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ impl Winner {
Winner::Ignore
}

fn __hash__(&self) -> u64 {
let value: u8 = self.clone().into();
value.into()
}

fn __getstate__(&self) -> PyResult<u8> {
Ok(self.clone().into())
}
Expand Down

0 comments on commit cb7e3d4

Please sign in to comment.