mirror of
https://github.com/clearml/clearml
synced 2025-02-07 21:33:25 +00:00
Fix argparse nargs passed in command line --nargs 1 2 should be stored as '[1, 2]' not as "['1', '2']"
This commit is contained in:
parent
6b8f21b30e
commit
0962e53f0b
@ -95,7 +95,7 @@ class _Arguments(object):
|
||||
else:
|
||||
args_dict = call_original_argparser(a_parser, args=a_args, namespace=a_namespace).__dict__
|
||||
defaults_ = {
|
||||
a.dest: cls.__cast_arg(args_dict.get(a.dest)) for a in actions
|
||||
a.dest: cls.__cast_arg(args_dict.get(a.dest), a.type) for a in actions
|
||||
}
|
||||
except Exception:
|
||||
# don't crash us if we failed parsing the inputs
|
||||
@ -539,10 +539,12 @@ class _Arguments(object):
|
||||
return dictionary
|
||||
|
||||
@classmethod
|
||||
def __cast_arg(cls, arg):
|
||||
def __cast_arg(cls, arg, dtype=None):
|
||||
if arg is None or callable(arg):
|
||||
return ''
|
||||
# If this an instance, just store the type
|
||||
if str(hex(id(arg))) in str(arg):
|
||||
return str(type(arg))
|
||||
if dtype in (float, int) and isinstance(arg, list):
|
||||
return [dtype(a) for a in arg]
|
||||
return arg
|
||||
|
@ -150,10 +150,11 @@ class PatchArgumentParser:
|
||||
if parsed_args_namespace and isinstance(parsed_args_namespace, Namespace):
|
||||
for k, v in parser._parsed_arg_string_lookup.items(): # noqa
|
||||
if hasattr(parsed_args_namespace, k):
|
||||
if isinstance(getattr(parsed_args_namespace, k, None), list) and not isinstance(v, list):
|
||||
v = [v]
|
||||
setattr(
|
||||
parsed_args_namespace, k,
|
||||
str([v] if (isinstance(getattr(parsed_args_namespace, k, None), list) and
|
||||
not isinstance(v, list)) else v)
|
||||
v if isinstance(v, list) else str(v)
|
||||
)
|
||||
|
||||
PatchArgumentParser._last_parsed_args = (PatchArgumentParser._last_parsed_args or []) + [parsed_args]
|
||||
|
Loading…
Reference in New Issue
Block a user