Skip to content

Commit 3a3d746

Browse files
committed
Prevent equality testing between Scancode and KeySym classes.
This would be bad for obvious reasons, but automatically converting them would cause hashing issues as well.
1 parent e4f0faa commit 3a3d746

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tcod/event.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,14 @@ def scancode(self) -> "Scancode":
16551655
"""
16561656
return self
16571657

1658+
def __eq__(self, other: Any) -> bool:
1659+
if isinstance(other, KeySym):
1660+
raise TypeError(
1661+
"Scancode and KeySym enums can not be compared directly."
1662+
" Convert one or the other to the same type."
1663+
)
1664+
return super().__eq__(other)
1665+
16581666

16591667
class KeySym(enum.IntEnum):
16601668
"""Key syms
@@ -2182,6 +2190,14 @@ def scancode(self) -> Scancode:
21822190
"""
21832191
return Scancode(lib.SDL_GetScancodeFromKey(self.value))
21842192

2193+
def __eq__(self, other: Any) -> bool:
2194+
if isinstance(other, Scancode):
2195+
raise TypeError(
2196+
"Scancode and KeySym enums can not be compared directly."
2197+
" Convert one or the other to the same type."
2198+
)
2199+
return super().__eq__(other)
2200+
21852201

21862202
__all__ = [ # noqa: F405
21872203
"Modifier",

0 commit comments

Comments
 (0)