Skip to content

Commit

Permalink
fix: issue where returndata integers could not be used in dictionary (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 30, 2024
1 parent 1fd2c64 commit ebe446c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ape/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit ebe446c

Please sign in to comment.