From 6783adaa3a016ae3cff2265956377c363aa30dc1 Mon Sep 17 00:00:00 2001 From: Zhiyuan Chen Date: Mon, 11 Sep 2023 12:02:57 +0000 Subject: [PATCH] no longer setattr value in __init__ if not specified Signed-off-by: Zhiyuan Chen --- chanfig/nested_dict.py | 10 ++++++---- chanfig/registry.py | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/chanfig/nested_dict.py b/chanfig/nested_dict.py index 66bceca1..f68c4ac3 100644 --- a/chanfig/nested_dict.py +++ b/chanfig/nested_dict.py @@ -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""" diff --git a/chanfig/registry.py b/chanfig/registry.py index e912e331..c630fd2b 100644 --- a/chanfig/registry.py +++ b/chanfig/registry.py @@ -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"""