From d483c3eb3361ded805f1b198afde008663ba6bfd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 3 Dec 2023 20:55:47 +0530 Subject: [PATCH] Fix literal field parsing --- kitty/config.py | 7 ++++++- kitty/options/utils.py | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kitty/config.py b/kitty/config.py index 67214175f..67ad73f5a 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -111,7 +111,12 @@ def finalize_keys(opts: Options, accumulate_bad_lines: Optional[List[BadLine]] = try: m = modes[defn.options.mode] except KeyError: - log_error(f'The keyboard mode {defn.options.mode} is unknown, ignoring the mapping: {defn}') + kerr = f'The keyboard mode {defn.options.mode} is unknown, ignoring the mapping' + if accumulate_bad_lines is None: + log_error(kerr) + else: + dl = defn.definition_location + accumulate_bad_lines.append(BadLine(dl.number, dl.line, KeyError(kerr), dl.file)) continue m.keymap[defn.trigger].append(defn) opts.keyboard_modes = modes diff --git a/kitty/options/utils.py b/kitty/options/utils.py index a4c6da923..c421cf762 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -1170,7 +1170,7 @@ class LiteralField(Generic[T]): def __set__(self, obj: object, value: str) -> None: if value not in self._vals: raise KeyError(f'Invalid value for {self._name[1:]}: {value!r}') - setattr(obj, self._name, value) + object.__setattr__(self, self._name, value) OnUnknown = Literal['beep', 'end', 'ignore', 'passthrough'] @@ -1182,8 +1182,8 @@ class KeyMapOptions: when_focus_on: str = '' new_mode: str = '' mode: str = '' - on_unknown = LiteralField[OnUnknown](get_args(OnUnknown)) - on_action = LiteralField[OnAction](get_args(OnAction)) + on_unknown: LiteralField[OnUnknown] = LiteralField[OnUnknown](get_args(OnUnknown)) + on_action: LiteralField[OnAction] = LiteralField[OnAction](get_args(OnAction)) default_key_map_options = KeyMapOptions() @@ -1259,7 +1259,7 @@ def parse_options_for_map(val: str) -> Tuple[KeyMapOptions, str]: k = k.replace('-', '_') expecting_arg = k if expecting_arg not in allowed_key_map_options: - raise KeyError(f'The map option {x} is unknown') + raise KeyError(f'The map option {x} is unknown. Allowed options: {", ".join(allowed_key_map_options)}') if sep == '=': object.__setattr__(ans, k, v) expecting_arg = ''