Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICV-mmengine_basecode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Schiffel
ICV-mmengine_basecode
Commits
b3d54481
Unverified
Commit
b3d54481
authored
3 years ago
by
Zaida Zhou
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[Fix] Fallback to use self registry if default_scope not found (#122)
parent
72cf4109
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mmengine/registry/registry.py
+9
-2
9 additions, 2 deletions
mmengine/registry/registry.py
tests/test_registry/test_registry.py
+4
-4
4 additions, 4 deletions
tests/test_registry/test_registry.py
with
13 additions
and
6 deletions
mmengine/registry/registry.py
+
9
−
2
View file @
b3d54481
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) OpenMMLab. All rights reserved.
import
inspect
import
inspect
import
sys
import
sys
import
warnings
from
collections.abc
import
Callable
from
collections.abc
import
Callable
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Tuple
,
Type
,
Union
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Tuple
,
Type
,
Union
...
@@ -382,8 +383,14 @@ class Registry:
...
@@ -382,8 +383,14 @@ class Registry:
root
=
self
.
_get_root_registry
()
root
=
self
.
_get_root_registry
()
registry
=
root
.
_search_child
(
default_scope
)
registry
=
root
.
_search_child
(
default_scope
)
if
registry
is
None
:
if
registry
is
None
:
raise
KeyError
(
# if `default_scope` can not be found, fallback to use self
f
'
{
default_scope
}
does not exist in the registry tree.
'
)
warnings
.
warn
(
f
'
Failed to search registry named
"
{
default_scope
}
"
.
'
'
As a workaround, the current registry is used to build
'
'
instance. This may cause unexpected failure when running
'
'
the built modules. Please check whether
'
f
'"
{
default_scope
}
"
is a correct scope.
'
)
registry
=
self
else
:
else
:
registry
=
self
registry
=
self
...
...
This diff is collapsed.
Click to expand it.
tests/test_registry/test_registry.py
+
4
−
4
View file @
b3d54481
...
@@ -341,14 +341,14 @@ class TestRegistry:
...
@@ -341,14 +341,14 @@ class TestRegistry:
assert
isinstance
(
MID_HOUNDS
.
build
(
b_cfg
),
Beagle
)
assert
isinstance
(
MID_HOUNDS
.
build
(
b_cfg
),
Beagle
)
# test `default_scope`
# test `default_scope`
# `default_scope` is an invalid scope
with
pytest
.
raises
(
KeyError
):
LITTLE_HOUNDS
.
build
(
b_cfg
,
default_scope
=
'
invalid_mid_hound
'
)
# switch the current registry to another registry
# switch the current registry to another registry
dog
=
LITTLE_HOUNDS
.
build
(
b_cfg
,
default_scope
=
'
mid_hound
'
)
dog
=
LITTLE_HOUNDS
.
build
(
b_cfg
,
default_scope
=
'
mid_hound
'
)
assert
isinstance
(
dog
,
Beagle
)
assert
isinstance
(
dog
,
Beagle
)
# `default_scope` can not be found
dog
=
MID_HOUNDS
.
build
(
b_cfg
,
default_scope
=
'
scope-not-found
'
)
assert
isinstance
(
dog
,
Beagle
)
def
test_repr
(
self
):
def
test_repr
(
self
):
CATS
=
Registry
(
'
cat
'
)
CATS
=
Registry
(
'
cat
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment