diff --git a/kitty/actions.py b/kitty/actions.py index b04f2648a..602ed9e3d 100644 --- a/kitty/actions.py +++ b/kitty/actions.py @@ -2,7 +2,7 @@ # License: GPLv3 Copyright: 2021, Kovid Goyal import inspect -from typing import NamedTuple, cast +from typing import Any, NamedTuple from .boss import Boss from .tabs import Tab @@ -39,18 +39,19 @@ def get_all_actions() -> dict[ActionGroup, list[Action]]: ans: dict[ActionGroup, list[Action]] = {} - def is_action(x: object) -> bool: + def is_action(x: Any) -> bool: return isinstance(getattr(x, 'action_spec', None), ActionSpec) - def as_action(x: object) -> Action: + def as_action(x: Any) -> Action: spec: ActionSpec = getattr(x, 'action_spec') doc = inspect.cleandoc(spec.doc) lines = doc.splitlines() first = lines.pop(0) short_help = first long_help = '\n'.join(lines).strip() - assert spec.group in groups - return Action(getattr(x, '__name__'), cast(ActionGroup, spec.group), short_help, long_help) + if spec.group not in groups: + raise KeyError(f'Unknown action type: {spec.group}') + return Action(getattr(x, '__name__'), spec.group, short_help, long_help) seen = set() for cls in (Window, Tab, Boss): diff --git a/kitty/open_actions.py b/kitty/open_actions.py index 4cb78ed4b..715a40cd9 100644 --- a/kitty/open_actions.py +++ b/kitty/open_actions.py @@ -7,7 +7,7 @@ import posixpath import shlex from collections.abc import Iterable, Iterator from contextlib import suppress -from typing import Any, NamedTuple, cast +from typing import Any, NamedTuple from urllib.parse import ParseResult, unquote, urlparse from .conf.utils import KeyAction, to_cmdline_implementation @@ -56,7 +56,7 @@ def parse(lines: Iterable[str]) -> Iterator[OpenAction]: elif key in ('mime', 'ext', 'protocol', 'file', 'path', 'url', 'fragment_matches'): if key != 'url': rest = rest.lower() - match_criteria.append(MatchCriteria(cast(MatchType, key), rest)) + match_criteria.append(MatchCriteria(key, rest)) elif key == 'action_alias': try: alias_name, alias_val = rest.split(maxsplit=1)