From 81420ad8944dfd95d96c09febb23c91bee841e45 Mon Sep 17 00:00:00 2001 From: Zhiyuan Chen Date: Thu, 30 Nov 2023 07:34:39 +0000 Subject: [PATCH] support passing override in Registry.register Signed-off-by: Zhiyuan Chen --- chanfig/registry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chanfig/registry.py b/chanfig/registry.py index 3e120117..530a26eb 100644 --- a/chanfig/registry.py +++ b/chanfig/registry.py @@ -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. @@ -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()