summaryrefslogtreecommitdiff
path: root/qutebrowser/keyinput/keyutils.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2019-09-12 11:53:36 +0200
committerFlorian Bruhin <me@the-compiler.org>2019-09-12 16:32:56 +0200
commit74cbb5add0a4647555933ffd66e79d4c5c0ae3f8 (patch)
treef8109fb1c5dbd73c40161c445b5d25aa81b94681 /qutebrowser/keyinput/keyutils.py
parentf8689774a0f6f6b844853c0658849573c4d668b8 (diff)
downloadqutebrowser-74cbb5add0a4647555933ffd66e79d4c5c0ae3f8.tar.gz
qutebrowser-74cbb5add0a4647555933ffd66e79d4c5c0ae3f8.zip
Make KeyInfo hashable
This way, we can store the real KeyInfo objects in BindingTrie instead of having to use .to_int().
Diffstat (limited to 'qutebrowser/keyinput/keyutils.py')
-rw-r--r--qutebrowser/keyinput/keyutils.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/qutebrowser/keyinput/keyutils.py b/qutebrowser/keyinput/keyutils.py
index 97159706f..f4759fb74 100644
--- a/qutebrowser/keyinput/keyutils.py
+++ b/qutebrowser/keyinput/keyutils.py
@@ -347,7 +347,7 @@ def _parse_single_key(keystr):
return 'Shift+' + keystr if keystr.isupper() else keystr
-@attr.s
+@attr.s(frozen=True, hash=False)
class KeyInfo:
"""A key with optional modifiers.
@@ -364,6 +364,14 @@ class KeyInfo:
def from_event(cls, e):
return cls(_remap_unicode(e.key(), e.text()), e.modifiers())
+ def __hash__(self):
+ """Convert KeyInfo to int before hashing.
+
+ This is needed as a WORKAROUND because enum members aren't hashable
+ with PyQt 5.7.
+ """
+ return hash(self.to_int())
+
def __str__(self):
"""Convert this KeyInfo to a meaningful name.