diff options
author | Florian Bruhin <me@the-compiler.org> | 2019-09-12 11:53:36 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2019-09-12 16:32:56 +0200 |
commit | 74cbb5add0a4647555933ffd66e79d4c5c0ae3f8 (patch) | |
tree | f8109fb1c5dbd73c40161c445b5d25aa81b94681 /qutebrowser/keyinput/keyutils.py | |
parent | f8689774a0f6f6b844853c0658849573c4d668b8 (diff) | |
download | qutebrowser-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.py | 10 |
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. |