Allow using a non-toal dict to init Options objects

This commit is contained in:
Kovid Goyal
2021-08-04 17:06:50 +05:30
parent 7090c24321
commit e50c26d1b9
3 changed files with 12 additions and 3 deletions

View File

@@ -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, ...]: