Skip to content
Snippets Groups Projects
Unverified Commit 16058fdb authored by Zaida Zhou's avatar Zaida Zhou Committed by GitHub
Browse files

[Fix] Fix RecursionError when key is invalid (#220)

* [Fix] Fix RecursionError when key is invalid

* refine comments
parent 50078256
No related branches found
No related tags found
No related merge requests found
......@@ -301,7 +301,7 @@ class Registry:
Args:
key (str): Name of the registered item, e.g., the class name in
string format.
string format.
Returns:
Type or None: Return the corresponding class if ``key`` exists,
......@@ -355,7 +355,14 @@ class Registry:
scope_name = scope
else:
root = self._get_root_registry()
obj_cls = root.get(key)
if scope != root._scope and scope not in root._children:
# If not skip directly, `root.get(key)` will recursively
# call itself until RecursionError is thrown.
pass
else:
obj_cls = root.get(key)
if obj_cls is not None:
logger: MMLogger = MMLogger.get_current_instance()
logger.info(
......
......@@ -281,6 +281,16 @@ class TestRegistry:
assert HOUNDS.get('samoyed.little_samoyed.LittlePedigreeSamoyed'
) is LittlePedigreeSamoyed
# invalid keys
# GoldenRetrieverererer can not be found at LITTLE_HOUNDS modules
assert LITTLE_HOUNDS.get('GoldenRetrieverererer') is None
# samoyedddd is not a child of DOGS
assert DOGS.get('samoyedddd.PedigreeSamoyed') is None
# samoyed is a child of DOGS but LittlePedigreeSamoyed can not be found
# at SAMOYEDS modules
assert DOGS.get('samoyed.LittlePedigreeSamoyed') is None
assert LITTLE_HOUNDS.get('mid_hound.PedigreeSamoyedddddd') is None
def test_search_child(self):
# Hierarchical Registry
# DOGS
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment