diff --git a/proto/enums.py b/proto/enums.py index 067d9674..6f13d32e 100644 --- a/proto/enums.py +++ b/proto/enums.py @@ -112,6 +112,9 @@ def _comparable(self, other): # Avoid 'isinstance' to prevent other IntEnums from matching return type(other) in (type(self), int) + def __hash__(self): + return hash(self.value) + def __eq__(self, other): if not self._comparable(other): return NotImplemented diff --git a/tests/test_enum_total_ordering.py b/tests/test_enum_total_ordering.py index a459e6b0..ad7a3691 100644 --- a/tests/test_enum_total_ordering.py +++ b/tests/test_enum_total_ordering.py @@ -85,3 +85,9 @@ def test_total_ordering_w_int(int_val): assert to_compare <= int_val assert not to_compare > int_val assert to_compare >= int_val + + +def test_hashing(): + to_hash = enums_test.OneEnum.SOME_VALUE + + {to_hash: "testing"} # no raise