diff --git a/src/ape/types/__init__.py b/src/ape/types/__init__.py index 066475e96f..94ddf2033a 100644 --- a/src/ape/types/__init__.py +++ b/src/ape/types/__init__.py @@ -500,6 +500,9 @@ def __eq__(self, other: Any) -> bool: # Try from the other end, if hasn't already. return NotImplemented + def __hash__(self) -> int: + return hash(int(self)) + @classmethod def __get_pydantic_core_schema__(cls, value, handler=None) -> CoreSchema: return no_info_plain_validator_function( diff --git a/tests/functional/test_types.py b/tests/functional/test_types.py index 4e5ed11bd3..3163953c62 100644 --- a/tests/functional/test_types.py +++ b/tests/functional/test_types.py @@ -195,3 +195,9 @@ class MyAnnotatedModel(BaseModel): for actual in (model.val, model.val_optional, model.val_in_dict["value"]): for ex in (value, expected): assert actual == ex + + def test_hashable(self): + mapping: dict[int, str] = {0: "0", 1: "1"} + key = CurrencyValueComparable(0) + assert key in mapping + assert mapping[key] == "0"