Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] fix raise error bug in registering multiple names #949

Merged
merged 5 commits into from
Apr 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions mmcv/utils/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
import warnings

import inspect
from functools import partial

from .misc import is_seq_of
Expand Down Expand Up @@ -239,11 +240,6 @@ def _register_module(self, module_class, module_name=None, force=False):
module_name = module_class.__name__
if isinstance(module_name, str):
module_name = [module_name]
else:
assert is_seq_of(
module_name,
str), ('module_name should be either of None, an '
f'instance of str or list, but got {type(module_name)}')
for name in module_name:
if not force and name in self._module_dict:
raise KeyError(f'{name} is already registered '
Expand Down Expand Up @@ -304,8 +300,10 @@ def register_module(self, name=None, force=False, module=None):
return module

# raise the error ahead of time
if not (name is None or isinstance(name, str)):
raise TypeError(f'name must be a str, but got {type(name)}')
if not (name is None or isinstance(name, str) or is_seq_of(name, str)):
ZwwWayne marked this conversation as resolved.
Show resolved Hide resolved
raise TypeError(
'name must be either of None, an instance of str or list,'
ZwwWayne marked this conversation as resolved.
Show resolved Hide resolved
f' but got {type(name)}')

# use it as a decorator: @x.register_module()
def _register(cls):
Expand Down