The parser doesnt need the full defaults object
This commit is contained in:
parent
c1777b1098
commit
3b1d534f6d
@ -3,7 +3,7 @@
|
|||||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from typing import Any, Dict, Iterable, Optional, Tuple, Type, Union
|
from typing import Any, Dict, FrozenSet, Iterable, Optional, Tuple, Type, Union
|
||||||
|
|
||||||
from kitty.cli_stub import DiffCLIOptions
|
from kitty.cli_stub import DiffCLIOptions
|
||||||
from kitty.conf.definition import config_lines
|
from kitty.conf.definition import config_lines
|
||||||
@ -93,13 +93,16 @@ def special_handling(key: str, val: str, ans: Dict) -> bool:
|
|||||||
|
|
||||||
def parse_config(lines: Iterable[str], check_keys: bool = True) -> Dict[str, Any]:
|
def parse_config(lines: Iterable[str], check_keys: bool = True) -> Dict[str, Any]:
|
||||||
ans: Dict[str, Any] = {'key_definitions': {}}
|
ans: Dict[str, Any] = {'key_definitions': {}}
|
||||||
|
defs: Optional[FrozenSet] = None
|
||||||
|
if check_keys:
|
||||||
|
defs = frozenset(defaults._fields) # type: ignore
|
||||||
|
|
||||||
parse_config_base(
|
parse_config_base(
|
||||||
lines,
|
lines,
|
||||||
defaults,
|
defs,
|
||||||
all_options,
|
all_options,
|
||||||
special_handling,
|
special_handling,
|
||||||
ans,
|
ans,
|
||||||
check_keys=check_keys
|
|
||||||
)
|
)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|||||||
@ -182,16 +182,14 @@ def _parse(
|
|||||||
|
|
||||||
def parse_config_base(
|
def parse_config_base(
|
||||||
lines: Iterable[str],
|
lines: Iterable[str],
|
||||||
defaults: Any,
|
all_option_names: Optional[FrozenSet],
|
||||||
all_options: Dict[str, Any],
|
all_options: Dict[str, Any],
|
||||||
special_handling: Callable,
|
special_handling: Callable,
|
||||||
ans: Dict[str, Any],
|
ans: Dict[str, Any],
|
||||||
check_keys: bool = True,
|
|
||||||
accumulate_bad_lines: Optional[List[BadLine]] = None
|
accumulate_bad_lines: Optional[List[BadLine]] = None
|
||||||
) -> None:
|
) -> None:
|
||||||
all_keys: Optional[FrozenSet[str]] = defaults._asdict() if check_keys else None
|
|
||||||
_parse(
|
_parse(
|
||||||
lines, create_type_converter(all_options), special_handling, ans, all_keys, accumulate_bad_lines
|
lines, create_type_converter(all_options), special_handling, ans, all_option_names, accumulate_bad_lines
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from contextlib import contextmanager, suppress
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import (
|
from typing import (
|
||||||
Any, Callable, Dict, Generator, Iterable, List, NamedTuple, Optional,
|
Any, Callable, Dict, Generator, Iterable, List, NamedTuple, Optional,
|
||||||
Sequence, Set, Tuple, Type, Union
|
Sequence, Set, Tuple, Type, Union, FrozenSet
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import fast_data_types as defines
|
from . import fast_data_types as defines
|
||||||
@ -684,9 +684,9 @@ def parse_config(lines: Iterable[str], check_keys: bool = True, accumulate_bad_l
|
|||||||
'env': {}, 'kitten_aliases': {}, 'font_features': {}, 'mouse_mappings': [],
|
'env': {}, 'kitten_aliases': {}, 'font_features': {}, 'mouse_mappings': [],
|
||||||
'mousemap': {}
|
'mousemap': {}
|
||||||
}
|
}
|
||||||
defs: Optional[OptionsStub] = None
|
defs: Optional[FrozenSet] = None
|
||||||
if check_keys:
|
if check_keys:
|
||||||
defs = defaults
|
defs = frozenset(defaults._fields) # type: ignore
|
||||||
|
|
||||||
parse_config_base(
|
parse_config_base(
|
||||||
lines,
|
lines,
|
||||||
@ -694,7 +694,6 @@ def parse_config(lines: Iterable[str], check_keys: bool = True, accumulate_bad_l
|
|||||||
all_options,
|
all_options,
|
||||||
special_handling,
|
special_handling,
|
||||||
ans,
|
ans,
|
||||||
check_keys=check_keys,
|
|
||||||
accumulate_bad_lines=accumulate_bad_lines
|
accumulate_bad_lines=accumulate_bad_lines
|
||||||
)
|
)
|
||||||
return ans
|
return ans
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user