Skip to content

Commit

Permalink
make Registry default factory to Registr
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed Aug 25, 2024
1 parent 2d20df8 commit 60ad059
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chanfig/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def __init__(
self.setattr("key", key)
if default is not None:
self.setattr("default", default)
self.setattr("default_factory", Registry)

def register(
self, component: Any = Null, name: Any = Null, override: bool = False, default: bool = False
Expand Down Expand Up @@ -201,7 +202,10 @@ def lookup(self, name: str, default: Any = Null) -> Any:

if default is Null:
default = self.getattr("default", Null)
return self.get(name, default)
element = self.get(name, default)
if isinstance(element, Registry):
return element.getattr("default")
return element

@staticmethod
def init(cls: Callable, *args: Any, **kwargs: Any) -> Any: # pylint: disable=W0211
Expand Down

0 comments on commit 60ad059

Please sign in to comment.