From 94412f72d807bf5268ab87ac84f9eff50ed4cfb3 Mon Sep 17 00:00:00 2001 From: Qian Zhao <112053249+C1rN09@users.noreply.github.com> Date: Wed, 31 Aug 2022 13:53:32 +0800 Subject: [PATCH] [Fix] Exception while building registered function (#491) --- mmengine/registry/build_functions.py | 3 ++- tests/test_registry/test_registry.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mmengine/registry/build_functions.py b/mmengine/registry/build_functions.py index 246e077e..be79dd26 100644 --- a/mmengine/registry/build_functions.py +++ b/mmengine/registry/build_functions.py @@ -114,7 +114,8 @@ def build_from_cfg( # If `obj_cls` inherits from `ManagerMixin`, it should be # instantiated by `ManagerMixin.get_instance` to ensure that it # can be accessed globally. - if issubclass(obj_cls, ManagerMixin): # type: ignore + if inspect.isclass(obj_cls) and \ + issubclass(obj_cls, ManagerMixin): # type: ignore obj = obj_cls.get_instance(**args) # type: ignore else: obj = obj_cls(**args) # type: ignore diff --git a/tests/test_registry/test_registry.py b/tests/test_registry/test_registry.py index 6f0cbe57..1829920f 100644 --- a/tests/test_registry/test_registry.py +++ b/tests/test_registry/test_registry.py @@ -339,6 +339,13 @@ class TestRegistry: registries = self._build_registry() DOGS, HOUNDS, LITTLE_HOUNDS, MID_HOUNDS, SAMOYEDS = registries[:5] + @DOGS.register_module() + def bark(times=1): + return ' '.join(['woof'] * times) + + bark_cfg = cfg_type(dict(type='bark', times=3)) + assert DOGS.build(bark_cfg) == 'woof woof woof' + @DOGS.register_module() class GoldenRetriever: pass -- GitLab