Skip to content

Commit

Permalink
support args and kwargs in apply
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed May 17, 2023
1 parent 1fc95e5 commit e7d9001
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chanfig/nested_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def all_items(self, prefix=""):

return all_items(self)

def apply(self, func: Callable) -> NestedDict:
def apply(self, func: Callable, *args, **kwargs) -> NestedDict:
r"""
Recursively apply a function to `NestedDict` and its children.
Expand All @@ -189,8 +189,8 @@ def apply(self, func: Callable) -> NestedDict:

for value in self.values():
if isinstance(value, NestedDict):
value.apply(func)
return func(self) or self
value.apply(func, *args, **kwargs)
return func(self, *args, **kwargs) or self

def get(self, name: Any, default: Any = Null) -> Any:
r"""
Expand Down

0 comments on commit e7d9001

Please sign in to comment.