From ebe446c89b0ffc7c42f5a6cec2fa57398ff7b04c Mon Sep 17 00:00:00 2001 From: antazoey Date: Fri, 30 Aug 2024 15:53:26 -0500 Subject: [PATCH] fix: issue where returndata integers could not be used in dictionary (#2260) --- src/ape/types/__init__.py | 3 +++ tests/functional/test_types.py | 6 ++++++ 2 files changed, 9 insertions(+) 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"