use dict comprehension to exclude unspecified options

This commit is contained in:
iclementine 2020-11-20 15:21:06 +08:00
parent 6101c6ac86
commit d190ce8d7f
1 changed files with 1 additions and 4 deletions

View File

@ -25,11 +25,8 @@ class Config(attrdict.AttrDict):
def merge_args(self, args): def merge_args(self, args):
args_dict = vars(args) args_dict = vars(args)
# remove options that is not passed via CLI
for k, v in args_dict.items():
if v is None:
args_dict.pop(k)
args_dict.pop("config") # exclude config file path args_dict.pop("config") # exclude config file path
args_dict = {k: v for k, v in args_dict.items() if v is not None}
nested_dict = flatdict.FlatDict(args_dict, delimiter=".").as_dict() nested_dict = flatdict.FlatDict(args_dict, delimiter=".").as_dict()
self.update(nested_dict) self.update(nested_dict)