Allow using a non-toal dict to init Options objects
This commit is contained in:
parent
7090c24321
commit
e50c26d1b9
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:
|
||||
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, ...]:
|
||||
|
||||
@ -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')
|
||||
|
||||
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:
|
||||
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, ...]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user