From e50c26d1b907efaf53fcfc790b32f6610be394a6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Aug 2021 17:06:50 +0530 Subject: [PATCH] Allow using a non-toal dict to init Options objects --- kittens/diff/options/types.py | 5 ++++- kitty/conf/generate.py | 5 ++++- kitty/options/types.py | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kittens/diff/options/types.py b/kittens/diff/options/types.py index fa51dcc90..34a7be191 100644 --- a/kittens/diff/options/types.py +++ b/kittens/diff/options/types.py @@ -72,8 +72,11 @@ class Options: def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None: if options_dict is not None: + null = object() for key in option_names: - setattr(self, key, options_dict[key]) + val = options_dict.get(key, null) + if val is not null: + setattr(self, key, val) @property def _fields(self) -> typing.Tuple[str, ...]: diff --git a/kitty/conf/generate.py b/kitty/conf/generate.py index f1e47e938..1737fae91 100644 --- a/kitty/conf/generate.py +++ b/kitty/conf/generate.py @@ -185,8 +185,11 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: if defn.has_color_table: a(' self.color_table = array(self.color_table.typecode, self.color_table)') a(' if options_dict is not None:') + a(' null = object()') a(' for key in option_names:') - a(' setattr(self, key, options_dict[key])') + a(' val = options_dict.get(key, null)') + a(' if val is not null:') + a(' setattr(self, key, val)') a('') a(' @property') diff --git a/kitty/options/types.py b/kitty/options/types.py index 058194f70..5e9778f69 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -608,8 +608,11 @@ class Options: def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None: self.color_table = array(self.color_table.typecode, self.color_table) if options_dict is not None: + null = object() for key in option_names: - setattr(self, key, options_dict[key]) + val = options_dict.get(key, null) + if val is not null: + setattr(self, key, val) @property def _fields(self) -> typing.Tuple[str, ...]: