mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Allow using a non-toal dict to init Options objects
This commit is contained in:
5
kittens/diff/options/types.py
generated
5
kittens/diff/options/types.py
generated
@@ -72,8 +72,11 @@ class Options:
|
|||||||
|
|
||||||
def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None:
|
def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None:
|
||||||
if options_dict is not None:
|
if options_dict is not None:
|
||||||
|
null = object()
|
||||||
for key in option_names:
|
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
|
@property
|
||||||
def _fields(self) -> typing.Tuple[str, ...]:
|
def _fields(self) -> typing.Tuple[str, ...]:
|
||||||
|
|||||||
@@ -185,8 +185,11 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
|
|||||||
if defn.has_color_table:
|
if defn.has_color_table:
|
||||||
a(' self.color_table = array(self.color_table.typecode, self.color_table)')
|
a(' self.color_table = array(self.color_table.typecode, self.color_table)')
|
||||||
a(' if options_dict is not None:')
|
a(' if options_dict is not None:')
|
||||||
|
a(' null = object()')
|
||||||
a(' for key in option_names:')
|
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('')
|
||||||
a(' @property')
|
a(' @property')
|
||||||
|
|||||||
5
kitty/options/types.py
generated
5
kitty/options/types.py
generated
@@ -608,8 +608,11 @@ class Options:
|
|||||||
def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None:
|
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)
|
self.color_table = array(self.color_table.typecode, self.color_table)
|
||||||
if options_dict is not None:
|
if options_dict is not None:
|
||||||
|
null = object()
|
||||||
for key in option_names:
|
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
|
@property
|
||||||
def _fields(self) -> typing.Tuple[str, ...]:
|
def _fields(self) -> typing.Tuple[str, ...]:
|
||||||
|
|||||||
Reference in New Issue
Block a user