From 74cabb36a424b67439185f1441be94b357c77695 Mon Sep 17 00:00:00 2001 From: Zhiyuan Chen Date: Wed, 20 Sep 2023 14:10:16 +0000 Subject: [PATCH] fix all_items error when bool(key) is False Signed-off-by: Zhiyuan Chen --- chanfig/flat_dict.py | 2 ++ chanfig/nested_dict.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chanfig/flat_dict.py b/chanfig/flat_dict.py index 01189b89..d5a36919 100644 --- a/chanfig/flat_dict.py +++ b/chanfig/flat_dict.py @@ -250,6 +250,8 @@ def set(self, name: Any, value: Any) -> None: 'liu' """ + if name is Null: + raise ValueError("name must not be null") if name in self and isinstance(self.get(name), Variable): self.get(name).set(value) else: diff --git a/chanfig/nested_dict.py b/chanfig/nested_dict.py index d280acc9..c0459fcc 100644 --- a/chanfig/nested_dict.py +++ b/chanfig/nested_dict.py @@ -183,9 +183,9 @@ def all_keys(self) -> Generator: delimiter = self.getattr("delimiter", ".") @wraps(self.all_keys) - def all_keys(self, prefix=""): + def all_keys(self, prefix=Null): for key, value in self.items(): - if prefix: + if prefix is not Null: key = str(prefix) + str(delimiter) + str(key) if isinstance(value, NestedDict): yield from all_keys(value, key) @@ -229,9 +229,9 @@ def all_items(self) -> Generator: delimiter = self.getattr("delimiter", ".") @wraps(self.all_items) - def all_items(self, prefix=""): + def all_items(self, prefix=Null): for key, value in self.items(): - if prefix: + if prefix is not Null: key = str(prefix) + str(delimiter) + str(key) if isinstance(value, NestedDict): yield from all_items(value, key)