Skip to content

Commit e0cd96d

Browse files
committed
Fix enum hashing issues.
These were always supposed to be hashable, but the equality check to prevent comparing enums of different types caused the hash function to be undefined.
1 parent 3fe86a5 commit e0cd96d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Added
1616
Changed
1717
- Using `libtcod 1.18.0`.
1818

19+
Fixed
20+
- `tcod.event.KeySym` and `tcod.event.Scancode ` can now be hashed.
21+
1922
12.3.2 - 2021-05-15
2023
-------------------
2124
Changed

tcod/event.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,10 @@ def __eq__(self, other: Any) -> bool:
16781678
)
16791679
return super().__eq__(other)
16801680

1681+
def __hash__(self) -> int:
1682+
# __eq__ was defined, so __hash__ must be defined.
1683+
return super().__hash__()
1684+
16811685

16821686
class KeySym(enum.IntEnum):
16831687
"""Keyboard constants based on their symbol.
@@ -2216,6 +2220,10 @@ def __eq__(self, other: Any) -> bool:
22162220
)
22172221
return super().__eq__(other)
22182222

2223+
def __hash__(self) -> int:
2224+
# __eq__ was defined, so __hash__ must be defined.
2225+
return super().__hash__()
2226+
22192227

22202228
__all__ = [ # noqa: F405
22212229
"Modifier",

0 commit comments

Comments
 (0)