summaryrefslogtreecommitdiff
path: root/src/flake8/options
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-05-19 17:01:14 -0700
committerAnthony Sottile <asottile@umich.edu>2019-05-19 17:31:04 -0700
commitfb7e9338cd06760a2f9096f976f0e246fc36a09e (patch)
treec2a2a2a907d7540eef0dbd633d6cb52cc50da14a /src/flake8/options
parentb6ba6d4d03109965d3cf5174d5c2e6868d7d92bb (diff)
downloadflake8-fb7e9338cd06760a2f9096f976f0e246fc36a09e.tar.gz
mypy now passes
Diffstat (limited to 'src/flake8/options')
-rw-r--r--src/flake8/options/config.py11
-rw-r--r--src/flake8/options/manager.py21
2 files changed, 20 insertions, 12 deletions
diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py
index 468341b..026618c 100644
--- a/src/flake8/options/config.py
+++ b/src/flake8/options/config.py
@@ -4,6 +4,7 @@ import configparser
import logging
import os.path
import sys
+from typing import Dict, List, Sequence, Tuple, Union
from flake8 import utils
@@ -54,12 +55,15 @@ class ConfigFileFinder(object):
# caches to avoid double-reading config files
self._local_configs = None
- self._local_found_files = []
+ self._local_found_files = [] # type: List[str]
self._user_config = None
- self._cli_configs = {}
+ # fmt: off
+ self._cli_configs = {} # type: Dict[str, configparser.RawConfigParser]
+ # fmt: on
@staticmethod
def _read_config(files):
+ # type: (Union[Sequence[str], str]) -> Tuple[configparser.RawConfigParser, List[str]] # noqa: E501
config = configparser.RawConfigParser()
if isinstance(files, (str, type(u""))):
files = [files]
@@ -83,6 +87,7 @@ class ConfigFileFinder(object):
return (config, found_files)
def cli_config(self, files):
+ # type: (str) -> configparser.RawConfigParser
"""Read and parse the config file specified on the command-line."""
if files not in self._cli_configs:
config, found_files = self._read_config(files)
@@ -379,7 +384,7 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False):
raw_paths = utils.parse_comma_separated_list(
config.get(section, "paths").strip()
)
- norm_paths = []
+ norm_paths = [] # type: List[str]
for base_dir in base_dirs:
norm_paths.extend(
path
diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py
index 0ded13a..5d21127 100644
--- a/src/flake8/options/manager.py
+++ b/src/flake8/options/manager.py
@@ -2,6 +2,7 @@
import collections
import logging
import optparse # pylint: disable=deprecated-module
+from typing import Any, Callable, Dict, List, Optional, Set
from flake8 import utils
@@ -108,7 +109,7 @@ class Option(object):
self.comma_separated_list = comma_separated_list
self.normalize_paths = normalize_paths
- self.config_name = None
+ self.config_name = None # type: Optional[str]
if parse_from_config:
if not long_option_name:
raise ValueError(
@@ -143,7 +144,7 @@ class Option(object):
"""Normalize the value based on the option configuration."""
if self.normalize_paths:
# Decide whether to parse a list of paths or a single path
- normalize = utils.normalize_path
+ normalize = utils.normalize_path # type: Callable[..., Any]
if self.comma_separated_list:
normalize = utils.normalize_paths
return normalize(value, *normalize_args)
@@ -200,13 +201,13 @@ class OptionManager(object):
self.parser = optparse.OptionParser(
prog=prog, version=version, usage=usage
)
- self.config_options_dict = {}
- self.options = []
+ self.config_options_dict = {} # type: Dict[str, Option]
+ self.options = [] # type: List[Option]
self.program_name = prog
self.version = version
- self.registered_plugins = set()
- self.extended_default_ignore = set()
- self.extended_default_select = set()
+ self.registered_plugins = set() # type: Set[PluginVersion]
+ self.extended_default_ignore = set() # type: Set[str]
+ self.extended_default_select = set() # type: Set[str]
@staticmethod
def format_plugin(plugin):
@@ -231,6 +232,7 @@ class OptionManager(object):
self.options.append(option)
if option.parse_from_config:
name = option.config_name
+ assert name is not None # nosec (for mypy)
self.config_options_dict[name] = option
self.config_options_dict[name.replace("_", "-")] = option
LOG.debug('Registered option "%s".', option)
@@ -326,7 +328,7 @@ class OptionManager(object):
values = self.parser.get_default_values()
self.parser.rargs = rargs
- self.parser.largs = largs = []
+ largs = [] # type: List[str]
self.parser.values = values
while rargs:
@@ -340,7 +342,8 @@ class OptionManager(object):
optparse.BadOptionError,
optparse.OptionValueError,
) as err:
- self.parser.largs.append(err.opt_str)
+ # TODO: https://gitlab.com/pycqa/flake8/issues/541
+ largs.append(err.opt_str) # type: ignore
args = largs + rargs
options, xargs = self.parser.check_values(values, args)