Skip to content

Commit

Permalink
raise KeyError if component not found in Registry
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, 2024
1 parent 83b0a5e commit 552f4c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions chanfig/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ def lookup(self, name: str, default: Any = Null) -> Any:

if default is Null:
default = self.getattr("default", Null)
element = self.get(name, default)
if isinstance(element, Registry):
return element.getattr("default")
return element
component = self.get(name, default)
if isinstance(component, Registry):
component = component.getattr("default")
if component is Null:
raise KeyError(f"Component with name {name} not registered.")
return component

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

0 comments on commit 552f4c1

Please sign in to comment.