summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric N. Vander Weele <ericvw@gmail.com>2019-08-30 15:17:16 -0400
committerEric N. Vander Weele <ericvw@gmail.com>2019-08-31 00:10:46 -0400
commitaadd09dd8bd91092b22b24b860d4ff2476313b1c (patch)
treeb8007cd8068739a67f84fbd6eb9d52d3916574dd /src
parentb231c10016fa50faf7ea87b2e0530655c2184bf4 (diff)
downloadflake8-aadd09dd8bd91092b22b24b860d4ff2476313b1c.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/flake8/options/manager.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py
index 3aea4ad..f745388 100644
--- a/src/flake8/options/manager.py
+++ b/src/flake8/options/manager.py
@@ -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