Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
88e01733
Unverified
Commit
88e01733
authored
Dec 14, 2021
by
Jiazhen Wang
Committed by
GitHub
Dec 14, 2021
Browse files
[Fix] fix config type inconsistency (#1575)
* [Fix] fix config type inconsistency * [Fix] Fix unit test
parent
250fadc2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
14 deletions
+22
-14
mmcv/utils/config.py
mmcv/utils/config.py
+13
-10
tests/data/config/delete.py
tests/data/config/delete.py
+2
-1
tests/test_utils/test_config.py
tests/test_utils/test_config.py
+7
-3
No files found.
mmcv/utils/config.py
View file @
88e01733
...
...
@@ -310,16 +310,19 @@ class Config:
if
len
(
b
)
<=
k
:
raise
KeyError
(
f
'Index
{
k
}
exceeds the length of list
{
b
}
'
)
b
[
k
]
=
Config
.
_merge_a_into_b
(
v
,
b
[
k
],
allow_list_keys
)
elif
isinstance
(
v
,
dict
)
and
k
in
b
and
not
v
.
pop
(
DELETE_KEY
,
False
):
elif
isinstance
(
v
,
dict
):
if
k
in
b
and
not
v
.
pop
(
DELETE_KEY
,
False
):
allowed_types
=
(
dict
,
list
)
if
allow_list_keys
else
dict
if
not
isinstance
(
b
[
k
],
allowed_types
):
raise
TypeError
(
f
'
{
k
}
=
{
v
}
in child config cannot inherit from base '
f
'because
{
k
}
is a dict in the child config but is of '
f
'type
{
type
(
b
[
k
])
}
in base config. You may set '
f
'`
{
DELETE_KEY
}
=True` to ignore the base config'
)
f
'
{
k
}
=
{
v
}
in child config cannot inherit from '
f
'base because
{
k
}
is a dict in the child config '
f
'but is of type
{
type
(
b
[
k
])
}
in base config. '
f
'You may set `
{
DELETE_KEY
}
=True` to ignore the '
f
'base config.'
)
b
[
k
]
=
Config
.
_merge_a_into_b
(
v
,
b
[
k
],
allow_list_keys
)
else
:
b
[
k
]
=
ConfigDict
(
v
)
else
:
b
[
k
]
=
v
return
b
...
...
tests/data/config/delete.py
View file @
88e01733
_base_
=
'./base.py'
item2
=
{
'b'
:
0
,
'_delete_'
:
True
}
item1
=
{
'a'
:
0
,
'_delete_'
:
True
}
item2
=
{
'b'
:
0
}
tests/test_utils/test_config.py
View file @
88e01733
...
...
@@ -10,7 +10,7 @@ from pathlib import Path
import
pytest
import
yaml
from
mmcv
import
Config
,
DictAction
,
dump
,
load
from
mmcv
import
Config
,
ConfigDict
,
DictAction
,
dump
,
load
data_path
=
osp
.
join
(
osp
.
dirname
(
osp
.
dirname
(
__file__
)),
'data'
)
...
...
@@ -347,12 +347,16 @@ def test_merge_delete():
cfg_file
=
osp
.
join
(
data_path
,
'config/delete.py'
)
cfg
=
Config
.
fromfile
(
cfg_file
)
# cfg.field
assert
cfg
.
item1
==
[
1
,
2
]
assert
cfg
.
item2
==
dict
(
b
=
0
)
assert
cfg
.
item1
==
dict
(
a
=
0
)
assert
cfg
.
item2
==
dict
(
a
=
0
,
b
=
0
)
assert
cfg
.
item3
is
True
assert
cfg
.
item4
==
'test'
assert
'_delete_'
not
in
cfg
.
item2
# related issue: https://github.com/open-mmlab/mmcv/issues/1570
assert
type
(
cfg
.
item1
)
==
ConfigDict
assert
type
(
cfg
.
item2
)
==
ConfigDict
def
test_merge_intermediate_variable
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment