Skip to content

Commit

Permalink
Merge db39f40 into 8beacd3
Browse files Browse the repository at this point in the history
  • Loading branch information
HAOCHENYE committed Mar 9, 2023
2 parents 8beacd3 + db39f40 commit 0cc116d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions mmengine/utils/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.
import inspect
import threading
import warnings
from collections import OrderedDict
from typing import Type, TypeVar

Expand Down Expand Up @@ -108,10 +109,11 @@ def get_instance(cls: Type[T], name: str, **kwargs) -> T:
if name not in instance_dict:
instance = cls(name=name, **kwargs) # type: ignore
instance_dict[name] = instance # type: ignore
else:
assert not kwargs, (
f'{cls} instance named of {name} has been created, the method '
'`get_instance` should not access any other arguments')
elif kwargs:
warnings.warn(
f'{cls} instance named of {name} has been created, '
'the method `get_instance` should not accept any other '
'arguments')
# Get latest instantiated instance or root instance.
_release_lock()
return instance_dict[name]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ def test_get_instance(self):
SubClassA.get_instance(name=1)
# `get_instance` should not accept other arguments if corresponding
# instance has been created.
with pytest.raises(AssertionError):
with pytest.warns(UserWarning):
SubClassA.get_instance('name2', a=1, b=2)

0 comments on commit 0cc116d

Please sign in to comment.