Update type signatures generated by gen/config.py

This commit is contained in:
Kovid Goyal 2025-02-11 22:22:57 +05:30
parent c7fb942c4c
commit fb54f1527f
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 21 additions and 18 deletions

View file

@ -52,7 +52,7 @@ def main(args: list[str]=sys.argv) -> None:
all_colors.append(opt.name)
patch_color_list('tools/cmd/at/set_colors.go', nullable_colors, 'NULLABLE')
patch_color_list('tools/themes/collection.go', all_colors, 'ALL')
nc = '\n, '.join(f'{x!r}' for x in nullable_colors)
nc = ',\n '.join(f'{x!r}' for x in nullable_colors)
write_output('kitty', definition, f'\nnullable_colors = frozenset({{\n {nc}\n}})\n')

View file

@ -59,7 +59,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
typ = option_type_as_str(rettype)
if isinstance(option, MultiOption):
typ = typ[typ.index('[') + 1:-1]
typ = typ.replace('Tuple', 'Dict', 1)
typ = typ.replace('tuple', 'dict', 1)
kq = ki_imports.search(typ)
if kq is not None:
kqi = kq.group(1)
@ -75,7 +75,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
def parser_function_declaration(option_name: str) -> None:
t('')
t(f' def {option_name}(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:')
t(f' def {option_name}(self, val: str, ans: dict[str, typing.Any]) -> None:')
for option in sorted(defn.iter_all_options(), key=lambda a: natural_keys(a.name)):
option_names.add(option.name)
@ -179,7 +179,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
rettype = th['return']
typ = option_type_as_str(rettype)
typ = typ[typ.index('[') + 1:-1]
a(f' {aname}: typing.List[{typ}] = []')
a(f' {aname}: list[{typ}] = []')
for imp in action.imports:
resolve_import(imp)
for fname, ftype in action.fields.items():
@ -198,11 +198,11 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
a(' ' + ', '.join(grp) + ',')
a(' ))')
a(' config_paths: typing.Tuple[str, ...] = ()')
a(' all_config_paths: typing.Tuple[str, ...] = ()')
a(' config_overrides: typing.Tuple[str, ...] = ()')
a(' config_paths: tuple[str, ...] = ()')
a(' all_config_paths: tuple[str, ...] = ()')
a(' config_overrides: tuple[str, ...] = ()')
a('')
a(' def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None:')
a(' def __init__(self, options_dict: dict[str, typing.Any] | None = None) -> None:')
if defn.has_color_table:
a(' self.color_table = array(self.color_table.typecode, self.color_table)')
a(' if options_dict is not None:')
@ -214,7 +214,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
a('')
a(' @property')
a(' def _fields(self) -> typing.Tuple[str, ...]:')
a(' def _fields(self) -> tuple[str, ...]:')
a(' return option_names')
a('')
@ -233,7 +233,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
a(' return ans')
a('')
a(' def _asdict(self) -> typing.Dict[str, typing.Any]:')
a(' def _asdict(self) -> dict[str, typing.Any]:')
a(' return {k: self._copy_of_val(k) for k in self}')
a('')
@ -246,7 +246,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
a(' return ans')
a('')
a(' def __getitem__(self, key: typing.Union[int, str]) -> typing.Any:')
a(' def __getitem__(self, key: int | str) -> typing.Any:')
a(' k = option_names[key] if isinstance(key, int) else key')
a(' try:')
a(' return getattr(self, k)')
@ -319,7 +319,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
t('')
t('')
t('def create_result_dict() -> typing.Dict[str, typing.Any]:')
t('def create_result_dict() -> dict[str, typing.Any]:')
t(' return {')
for oname in is_mutiple_vars:
t(f' {oname!r}: {{}},')
@ -329,10 +329,10 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
t('')
t('')
t(f'actions: typing.FrozenSet[str] = frozenset({tuple(defn.actions)!r})')
t(f'actions: frozenset[str] = frozenset({tuple(defn.actions)!r})')
t('')
t('')
t('def merge_result_dicts(defaults: typing.Dict[str, typing.Any], vals: typing.Dict[str, typing.Any]) -> typing.Dict[str, typing.Any]:')
t('def merge_result_dicts(defaults: dict[str, typing.Any], vals: dict[str, typing.Any]) -> dict[str, typing.Any]:')
t(' ans = {}')
t(' for k, v in defaults.items():')
t(' if isinstance(v, dict):')
@ -349,7 +349,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
t('parser = Parser()')
t('')
t('')
t('def parse_conf_item(key: str, val: str, ans: typing.Dict[str, typing.Any]) -> bool:')
t('def parse_conf_item(key: str, val: str, ans: dict[str, typing.Any]) -> bool:')
t(' func = getattr(parser, key, None)')
t(' if func is not None:')
t(' func(val, ans)')
@ -362,6 +362,7 @@ def generate_class(defn: Definition, loc: str) -> tuple[str, str]:
def output_imports(imports: set[tuple[str, str]], add_module_imports: bool = True) -> None:
a('# isort: skip_file')
a('import typing')
a('import collections.abc # noqa: F401, RUF100')
seen_mods = {'typing'}
mmap: dict[str, list[str]] = {}
for mod, name in imports:

View file

@ -2,6 +2,7 @@
# isort: skip_file
import typing
import collections.abc # noqa: F401, RUF100
from kitty.conf.utils import (
merge_dicts, positive_float, positive_int, python_string, to_bool, to_cmdline, to_color,
to_color_or_none, unit_float

View file

@ -2,6 +2,7 @@
# isort: skip_file
import typing
import collections.abc # noqa: F401, RUF100
from array import array
from kitty.constants import is_macos
import kitty.constants
@ -597,7 +598,7 @@ class Options:
tab_activity_symbol: str = ''
tab_bar_align: choices_for_tab_bar_align = 'left'
tab_bar_background: kitty.fast_data_types.Color | None = None
tab_bar_edge: int = 3
tab_bar_edge: int = 8
tab_bar_margin_color: kitty.fast_data_types.Color | None = None
tab_bar_margin_height: TabBarMarginHeight = TabBarMarginHeight(outer=0, inner=0)
tab_bar_margin_width: float = 0
@ -649,7 +650,7 @@ class Options:
menu_map: dict[tuple[str, ...], str] = {}
modify_font: dict[str, kitty.fonts.FontModification] = {}
narrow_symbols: dict[tuple[int, int], int] = {}
remote_control_password: dict[str, typing.Sequence[str]] = {}
remote_control_password: dict[str, collections.abc.Sequence[str]] = {}
symbol_map: dict[tuple[int, int], str] = {}
watcher: dict[str, str] = {}
map: list[kitty.options.utils.KeyDefinition] = []
@ -1056,4 +1057,4 @@ nullable_colors = frozenset({
})
secret_options = ('remote_control_password', 'file_transfer_confirmation_bypass')
secret_options = ('remote_control_password', 'file_transfer_confirmation_bypass')