aggregator: Simplify 'aggregate_options' function definition

The `values` parameter is safe to remove since it is not provided as an
argument by any callers and the remaining arguments are guaranteed to
always be provided by all callers.
This commit is contained in:
Eric N. Vander Weele 2019-11-03 01:11:43 +00:00 committed by Anthony Sottile
parent ff871fe656
commit 6c117cedd7

View file

@ -3,26 +3,30 @@
This holds the logic that uses the collected and merged config files and
applies the user-specified command-line configuration on top of it.
"""
import argparse
import logging
from typing import List, Tuple
from flake8.options import config
from flake8.options.manager import OptionManager
LOG = logging.getLogger(__name__)
def aggregate_options(manager, config_finder, arglist=None, values=None):
def aggregate_options(
manager, # type: OptionManager
config_finder, # type: config.ConfigFileFinder
argv, # type: List[str]
): # type: (...) -> Tuple[argparse.Namespace, List[str]]
"""Aggregate and merge CLI and config file options.
:param flake8.options.manager.OptionManager manager:
The instance of the OptionManager that we're presently using.
:param flake8.options.config.ConfigFileFinder config_finder:
The config file finder to use.
:param list arglist:
The list of arguments to pass to ``manager.parse_args``. In most cases
this will be None so ``parse_args`` uses ``sys.argv``. This is mostly
available to make testing easier.
:param argparse.Namespace values:
Previously parsed set of parsed options.
:param list argv:
The list of remaining command-line argumentsthat were unknown during
preliminary option parsing to pass to ``manager.parse_args``.
:returns:
Tuple of the parsed options and extra arguments returned by
``manager.parse_args``.
@ -30,10 +34,10 @@ def aggregate_options(manager, config_finder, arglist=None, values=None):
tuple(argparse.Namespace, list)
"""
# Get defaults from the option parser
default_values, _ = manager.parse_args([], values=values)
default_values, _ = manager.parse_args([])
# Get original CLI values so we can find additional config file paths and
# see if --config was specified.
original_values, _ = manager.parse_args(arglist)
original_values, _ = manager.parse_args(argv)
# Make our new configuration file mergerator
config_parser = config.MergedConfigParser(
@ -79,4 +83,4 @@ def aggregate_options(manager, config_finder, arglist=None, values=None):
setattr(default_values, dest_name, value)
# Finally parse the command-line options
return manager.parse_args(arglist, default_values)
return manager.parse_args(argv, default_values)