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
b8044770
Unverified
Commit
b8044770
authored
Apr 18, 2022
by
Vince Jankovics
Committed by
GitHub
Apr 18, 2022
Browse files
[Enhancement] Support None in DictAction (#1834)
* None parsing fixed for config * Formatting * Lower case none fix
parent
6f6b17e6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
mmcv/utils/config.py
mmcv/utils/config.py
+2
-0
tests/test_utils/test_config.py
tests/test_utils/test_config.py
+12
-3
No files found.
mmcv/utils/config.py
View file @
b8044770
...
...
@@ -638,6 +638,8 @@ class DictAction(Action):
pass
if
val
.
lower
()
in
[
'true'
,
'false'
]:
return
True
if
val
.
lower
()
==
'true'
else
False
if
val
==
'None'
:
return
None
return
val
@
staticmethod
...
...
tests/test_utils/test_config.py
View file @
b8044770
...
...
@@ -470,9 +470,18 @@ def test_dict_action():
with
pytest
.
raises
(
AssertionError
):
parser
.
parse_args
([
'--options'
,
'item2.a=[(a,b), [1,2], false'
])
# Normal values
args
=
parser
.
parse_args
(
[
'--options'
,
'item2.a=1'
,
'item2.b=0.1'
,
'item2.c=x'
,
'item3=false'
])
out_dict
=
{
'item2.a'
:
1
,
'item2.b'
:
0.1
,
'item2.c'
:
'x'
,
'item3'
:
False
}
args
=
parser
.
parse_args
([
'--options'
,
'item2.a=1'
,
'item2.b=0.1'
,
'item2.c=x'
,
'item3=false'
,
'item4=none'
,
'item5=None'
])
out_dict
=
{
'item2.a'
:
1
,
'item2.b'
:
0.1
,
'item2.c'
:
'x'
,
'item3'
:
False
,
'item4'
:
'none'
,
'item5'
:
None
,
}
assert
args
.
options
==
out_dict
cfg_file
=
osp
.
join
(
data_path
,
'config/a.py'
)
cfg
=
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