Skip to content

Commit

Permalink
support passing override in Registry.register
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiyuan Chen <[email protected]>
  • Loading branch information
ZhiyuanChen committed Nov 30, 2023
1 parent b7c0103 commit 81420ad
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chanfig/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, override: bool | None = None, fallback: bool | None = None):
if override is not None:
self.setattr("override", override)

def register(self, component: Any = None, name: Any | None = None) -> Callable:
def register(self, component: Any = None, name: Any | None = None, override: bool = False) -> Callable:
r"""
Register a new component.
Expand Down Expand Up @@ -125,7 +125,7 @@ def register(self, component: Any = None, name: Any | None = None) -> Callable:
)
"""

if name in self and not self.override:
if name in self and not (override or self.override):
raise ValueError(f"Component with name {name} already registered.")

# Registry.register()
Expand Down

0 comments on commit 81420ad

Please sign in to comment.