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
a3ae7817
Unverified
Commit
a3ae7817
authored
Jun 04, 2020
by
Jerry Jiarui XU
Committed by
GitHub
Jun 04, 2020
Browse files
add reserved key in config (#315)
parent
35ba1528
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
0 deletions
+11
-0
mmcv/utils/config.py
mmcv/utils/config.py
+4
-0
tests/data/config/g.py
tests/data/config/g.py
+1
-0
tests/test_config.py
tests/test_config.py
+6
-0
No files found.
mmcv/utils/config.py
View file @
a3ae7817
...
...
@@ -14,6 +14,7 @@ from .path import check_file_exist
BASE_KEY
=
'_base_'
DELETE_KEY
=
'_delete_'
RESERVED_KEYS
=
[
'filename'
,
'text'
,
'pretty_text'
]
class
ConfigDict
(
Dict
):
...
...
@@ -184,6 +185,9 @@ class Config(object):
elif
not
isinstance
(
cfg_dict
,
dict
):
raise
TypeError
(
'cfg_dict must be a dict, but '
f
'got
{
type
(
cfg_dict
)
}
'
)
for
key
in
cfg_dict
:
if
key
in
RESERVED_KEYS
:
raise
KeyError
(
f
'
{
key
}
is reserved for config file'
)
super
(
Config
,
self
).
__setattr__
(
'_cfg_dict'
,
ConfigDict
(
cfg_dict
))
super
(
Config
,
self
).
__setattr__
(
'_filename'
,
filename
)
...
...
tests/data/config/g.py
0 → 100644
View file @
a3ae7817
filename
=
'reserved.py'
tests/test_config.py
View file @
a3ae7817
...
...
@@ -266,3 +266,9 @@ def test_dump_mapping():
text_cfg
=
Config
.
fromfile
(
text_cfg_filename
)
assert
text_cfg
.
_cfg_dict
==
cfg
.
_cfg_dict
def
test_reserved_key
():
cfg_file
=
osp
.
join
(
osp
.
dirname
(
__file__
),
'data/config/g.py'
)
with
pytest
.
raises
(
KeyError
):
Config
.
fromfile
(
cfg_file
)
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