Skip to content

Commit

Permalink
fix all_items error when bool(key) is False
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed Sep 20, 2023
1 parent ce4b229 commit 74cabb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions chanfig/flat_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions chanfig/nested_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 74cabb3

Please sign in to comment.