[Fix] Exception while building registered function (#491)

pull/497/head
Qian Zhao 2022-08-31 13:53:32 +08:00 committed by GitHub
parent 68b6b542eb
commit 94412f72d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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