Skip to content

Commit

Permalink
no longer setattr value in __init__ if not specified
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed Sep 14, 2023
1 parent 53fd169 commit 6783ada
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions chanfig/nested_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ def __init__(
self,
*args: Any,
default_factory: Callable | None = None,
convert_mapping: bool = False,
fallback: bool = False,
convert_mapping: bool | None = None,
fallback: bool | None = None,
**kwargs: Any,
) -> None:
super().__init__(default_factory)
self.merge(*args, **kwargs)
self.setattr("convert_mapping", convert_mapping)
self.setattr("fallback", fallback)
if convert_mapping is not None:
self.setattr("convert_mapping", convert_mapping)
if fallback is not None:
self.setattr("fallback", fallback)

def all_keys(self) -> Generator:
r"""
Expand Down
5 changes: 3 additions & 2 deletions chanfig/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ class Registry(NestedDict): # type: ignore

override: bool = False

def __init__(self, override: bool = False, fallback: bool = False):
def __init__(self, override: bool | None = None, fallback: bool | None = None):
super().__init__(fallback=fallback)
self.setattr("override", override)
if override is not None:
self.setattr("override", override)

def register(self, component: Any = None, name: Any | None = None) -> Callable:
r"""
Expand Down

0 comments on commit 6783ada

Please sign in to comment.