Set configuration file-provided values via ArgumentParser.set_defaults()

When calling `ArgumentParser.parse_args()` with the `namespace`
argument, command-line options are just added to the  namespace without
going through any of the argument parsing and type conversion logic
(e.g., the `type` keyword argument of `ArgumentParser.add_argument()`).
In other words, it is assumed that a namespace is well-formed from a
previous invocation of `ArgumentParser.parse_args()`.

The `values` parameter is intended to be values already-provided from
configuration files.  To take advantage of the logic defined by
`ArgumentParser.add_argument()`,  utilize
`ArgumentParser.set_defaults()` instead.
This commit is contained in:
Eric N. Vander Weele 2019-08-30 15:17:16 -04:00
parent b231c10016
commit aadd09dd8b
2 changed files with 11 additions and 1 deletions

View file

@ -437,7 +437,9 @@ class OptionManager(object):
assert isinstance( # nosec (for bandit)
self.parser, argparse.ArgumentParser
), self.parser
parsed_args = self.parser.parse_args(args, values)
if values:
self.parser.set_defaults(**vars(values))
parsed_args = self.parser.parse_args(args)
# TODO: refactor callers to not need this
return parsed_args, parsed_args.filenames