Resolve invalid keys to KC.NO instead of ValueError
This commit is contained in:
parent
2ccad46e26
commit
fd700cff44
@ -475,7 +475,9 @@ class KeyAttrDict:
|
|||||||
break
|
break
|
||||||
|
|
||||||
if not maybe_key:
|
if not maybe_key:
|
||||||
raise ValueError(f'Invalid key: {name}')
|
if debug.enabled:
|
||||||
|
debug(f'Invalid key: {name}')
|
||||||
|
return KC.NO
|
||||||
|
|
||||||
if debug.enabled:
|
if debug.enabled:
|
||||||
debug(f'{name}: {maybe_key}')
|
debug(f'{name}: {maybe_key}')
|
||||||
|
@ -54,7 +54,7 @@ class HoldTap(Module):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.key_buffer = []
|
self.key_buffer = []
|
||||||
self.key_states = {}
|
self.key_states = {}
|
||||||
if not KC.get('HT'):
|
if KC.get('HT') == KC.NO:
|
||||||
make_argumented_key(
|
make_argumented_key(
|
||||||
validator=HoldTapKeyMeta,
|
validator=HoldTapKeyMeta,
|
||||||
names=('HT',),
|
names=('HT',),
|
||||||
|
@ -42,12 +42,11 @@ class Phrase:
|
|||||||
self._characters: list[Character] = []
|
self._characters: list[Character] = []
|
||||||
self._index: int = 0
|
self._index: int = 0
|
||||||
for char in string:
|
for char in string:
|
||||||
try:
|
key_code = KC[char]
|
||||||
key_code = KC[char]
|
if key_code == KC.NO:
|
||||||
shifted = char.isupper() or key_code.has_modifiers == {2}
|
|
||||||
self._characters.append(Character(key_code, shifted))
|
|
||||||
except ValueError:
|
|
||||||
raise ValueError(f'Invalid character in dictionary: {char}')
|
raise ValueError(f'Invalid character in dictionary: {char}')
|
||||||
|
shifted = char.isupper() or key_code.has_modifiers == {2}
|
||||||
|
self._characters.append(Character(key_code, shifted))
|
||||||
|
|
||||||
def next_character(self) -> None:
|
def next_character(self) -> None:
|
||||||
'''Increment the current index for this phrase'''
|
'''Increment the current index for this phrase'''
|
||||||
|
@ -123,12 +123,10 @@ class TestKeys_dot(unittest.TestCase):
|
|||||||
assert primary_key is secondary_key
|
assert primary_key is secondary_key
|
||||||
|
|
||||||
def test_invalid_key_upper(self):
|
def test_invalid_key_upper(self):
|
||||||
with self.assertRaises(ValueError):
|
assert KC.INVALID_KEY == KC.NO
|
||||||
KC.INVALID_KEY
|
|
||||||
|
|
||||||
def test_invalid_key_lower(self):
|
def test_invalid_key_lower(self):
|
||||||
with self.assertRaises(ValueError):
|
assert KC.invalid_key == KC.NO
|
||||||
KC.invalid_key
|
|
||||||
|
|
||||||
def test_custom_key(self):
|
def test_custom_key(self):
|
||||||
created = make_key(
|
created = make_key(
|
||||||
@ -168,12 +166,10 @@ class TestKeys_index(unittest.TestCase):
|
|||||||
assert upper_key is lower_key
|
assert upper_key is lower_key
|
||||||
|
|
||||||
def test_invalid_key_upper(self):
|
def test_invalid_key_upper(self):
|
||||||
with self.assertRaises(ValueError):
|
assert KC.INVALID_KEY == KC.NO
|
||||||
KC['NOT_A_VALID_KEY']
|
|
||||||
|
|
||||||
def test_invalid_key_lower(self):
|
def test_invalid_key_lower(self):
|
||||||
with self.assertRaises(ValueError):
|
assert KC.invalid_key == KC.NO
|
||||||
KC['not_a_valid_key']
|
|
||||||
|
|
||||||
def test_custom_key(self):
|
def test_custom_key(self):
|
||||||
created = make_key(
|
created = make_key(
|
||||||
@ -218,10 +214,10 @@ class TestKeys_get(unittest.TestCase):
|
|||||||
assert primary_key is secondary_key
|
assert primary_key is secondary_key
|
||||||
|
|
||||||
def test_invalid_key_upper(self):
|
def test_invalid_key_upper(self):
|
||||||
assert KC.get('INVALID_KEY') is None
|
assert KC.get('INVALID_KEY') is KC.NO
|
||||||
|
|
||||||
def test_invalid_key_lower(self):
|
def test_invalid_key_lower(self):
|
||||||
assert KC.get('not_a_valid_key') is None
|
assert KC.get('not_a_valid_key') is KC.NO
|
||||||
|
|
||||||
def test_custom_key(self):
|
def test_custom_key(self):
|
||||||
created = make_key(
|
created = make_key(
|
||||||
|
Loading…
Reference in New Issue
Block a user