summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-02-19 15:10:46 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2016-02-19 15:10:46 -0600
commit69b8be71dca9f0d8b9a22189801a4a4c8328f07f (patch)
treeb1a1442c8b2311011a6779b0707846cb3be8fab6
parent85c199ea34d39bdb811249d26fc535a2228139c6 (diff)
downloadflake8-69b8be71dca9f0d8b9a22189801a4a4c8328f07f.tar.gz
Make pylint happier
-rw-r--r--flake8/__init__.py12
-rw-r--r--flake8/formatting/default.py2
-rw-r--r--flake8/main/cli.py15
-rw-r--r--flake8/options/aggregator.py3
-rw-r--r--flake8/options/config.py9
-rw-r--r--flake8/options/manager.py16
-rw-r--r--flake8/plugins/manager.py12
-rw-r--r--flake8/plugins/pyflakes.py23
-rw-r--r--flake8/style_guide.py8
-rw-r--r--flake8/utils.py9
-rw-r--r--tests/unit/test_config_file_finder.py4
11 files changed, 65 insertions, 48 deletions
diff --git a/flake8/__init__.py b/flake8/__init__.py
index a6520e4..996f036 100644
--- a/flake8/__init__.py
+++ b/flake8/__init__.py
@@ -10,8 +10,6 @@ This module
"""
import logging
-import sys
-
try:
from logging import NullHandler
except ImportError:
@@ -21,6 +19,7 @@ except ImportError:
def emit(self, record):
"""Do nothing."""
pass
+import sys
LOG = logging.getLogger(__name__)
LOG.addHandler(NullHandler())
@@ -51,7 +50,6 @@ def configure_logging(verbosity, filename=None,
If the name is "stdout" or "stderr" this will log to the appropriate
stream.
"""
- global LOG
if verbosity <= 0:
return
if verbosity > 2:
@@ -60,12 +58,14 @@ def configure_logging(verbosity, filename=None,
log_level = _VERBOSITY_TO_LOG_LEVEL[verbosity]
if not filename or filename in ('stderr', 'stdout'):
- handler = logging.StreamHandler(getattr(sys, filename))
+ fileobj = getattr(sys, filename or 'stderr')
+ handler = logging.StreamHandler
else:
- handler = logging.FileHandler(filename)
+ fileobj = filename
+ handler = logging.FileHandler
handler.setFormatter(logging.Formatter(logformat))
- LOG.addHandler(handler)
+ LOG.addHandler(handler(fileobj))
LOG.setLevel(log_level)
LOG.debug('Added a %s logging handler to logger root at %s',
filename, __name__)
diff --git a/flake8/formatting/default.py b/flake8/formatting/default.py
index e0686a0..bef8c88 100644
--- a/flake8/formatting/default.py
+++ b/flake8/formatting/default.py
@@ -18,6 +18,8 @@ class SimpleFormatter(base.BaseFormatter):
"""
+ error_format = None
+
def format(self, error):
"""Format and write error out.
diff --git a/flake8/main/cli.py b/flake8/main/cli.py
index 183b951..c9503f1 100644
--- a/flake8/main/cli.py
+++ b/flake8/main/cli.py
@@ -174,10 +174,11 @@ def main(argv=None):
# Parse out our options from our found config files and user-provided CLI
# options
- options, args = aggregator.aggregate_options(option_manager)
-
- # formatter = formatting_plugins.get(
- # options.format, formatting_plugins['default']
- # ).execute(options)
- # listener_trie = listening_plugins.build_notifier()
- # guide = style_guide.StyleGuide(options, args, listener_trie, formatter)
+ options, args = aggregator.aggregate_options(option_manager, argv)
+
+ formatter = formatting_plugins.get(
+ options.format, formatting_plugins['default']
+ ).execute(options)
+ listener_trie = listening_plugins.build_notifier()
+ guide = style_guide.StyleGuide(options, args, listener_trie, formatter)
+ guide.handle_error('E111', 'stdin', 1, 1, 'faketext')
diff --git a/flake8/options/aggregator.py b/flake8/options/aggregator.py
index 5c02730..b344cf0 100644
--- a/flake8/options/aggregator.py
+++ b/flake8/options/aggregator.py
@@ -71,5 +71,4 @@ def aggregate_options(manager, arglist=None, values=None):
setattr(default_values, dest_name, value)
# Finally parse the command-line options
- final_values, args = manager.parse_args(arglist, default_values)
- return final_values, args
+ return manager.parse_args(arglist, default_values)
diff --git a/flake8/options/config.py b/flake8/options/config.py
index 2484cdd..ecc40f7 100644
--- a/flake8/options/config.py
+++ b/flake8/options/config.py
@@ -66,7 +66,7 @@ class ConfigFileFinder(object):
LOG.debug('Found cli configuration files: %s', found_files)
return config
- def generate_possible_local_config_files(self):
+ def generate_possible_local_files(self):
"""Find and generate all local config files."""
tail = self.tail
parent = self.parent
@@ -84,7 +84,7 @@ class ConfigFileFinder(object):
"""Find all local config files which actually exist.
Filter results from
- :meth:`~ConfigFileFinder.generate_possible_local_config_files` based
+ :meth:`~ConfigFileFinder.generate_possible_local_files` based
on whether the filename exists or not.
:returns:
@@ -93,11 +93,12 @@ class ConfigFileFinder(object):
:rtype:
[str]
"""
+ exists = os.path.exists
return [
filename
- for filename in self.generate_possible_local_config_files()
+ for filename in self.generate_possible_local_files()
if os.path.exists(filename)
- ] + list(filter(os.path.exists, self.extra_config_files))
+ ] + [f for f in self.extra_config_files if exists(f)]
def local_configs(self):
"""Parse all local config files into one config object."""
diff --git a/flake8/options/manager.py b/flake8/options/manager.py
index 9faaf7c..cb4c831 100644
--- a/flake8/options/manager.py
+++ b/flake8/options/manager.py
@@ -1,6 +1,6 @@
"""Option handling and Option management logic."""
import logging
-import optparse
+import optparse # pylint: disable=deprecated-module
from flake8 import utils
@@ -18,8 +18,7 @@ class Option(object):
metavar=None,
# Options below here are specific to Flake8
parse_from_config=False, comma_separated_list=False,
- normalize_paths=False,
- ):
+ normalize_paths=False):
"""Initialize an Option instance wrapping optparse.Option.
The following are all passed directly through to optparse.
@@ -69,12 +68,17 @@ class Option(object):
"""
self.short_option_name = short_option_name
self.long_option_name = long_option_name
- self.option_args = filter(None, (short_option_name, long_option_name))
+ self.option_args = [
+ x for x in (short_option_name, long_option_name) if x is not None
+ ]
self.option_kwargs = {
'action': action,
'default': default,
'type': type,
'dest': self._make_dest(dest),
+ 'nargs': nargs,
+ 'const': const,
+ 'choices': choices,
'callback': callback,
'callback_args': callback_args,
'callback_kwargs': callback_kwargs,
@@ -97,6 +101,8 @@ class Option(object):
'a long_option_name must also be specified.')
self.config_name = long_option_name[2:].replace('-', '_')
+ self._opt = None
+
def __repr__(self):
"""Simple representation of an Option class."""
return (
@@ -129,7 +135,7 @@ class Option(object):
def to_optparse(self):
"""Convert a Flake8 Option to an optparse Option."""
- if not hasattr(self, '_opt'):
+ if self._opt is None:
self._opt = optparse.Option(*self.option_args,
**self.option_kwargs)
return self._opt
diff --git a/flake8/plugins/manager.py b/flake8/plugins/manager.py
index 3a20b91..21171ef 100644
--- a/flake8/plugins/manager.py
+++ b/flake8/plugins/manager.py
@@ -57,7 +57,7 @@ class Plugin(object):
def execute(self, *args, **kwargs):
r"""Call the plugin with \*args and \*\*kwargs."""
- return self.plugin(*args, **kwargs)
+ return self.plugin(*args, **kwargs) # pylint: disable=not-callable
def _load(self, verify_requirements):
# Avoid relying on hasattr() here.
@@ -134,7 +134,7 @@ class Plugin(object):
)
-class PluginManager(object):
+class PluginManager(object): # pylint: disable=too-few-public-methods
"""Find and manage plugins consistently."""
def __init__(self, namespace, verify_requirements=False):
@@ -188,6 +188,8 @@ class PluginManager(object):
class PluginTypeManager(object):
"""Parent class for most of the specific plugin types."""
+ namespace = None
+
def __init__(self):
"""Initialize the plugin type's manager."""
self.manager = PluginManager(self.namespace)
@@ -232,6 +234,7 @@ class PluginTypeManager(object):
@staticmethod
def _generate_call_function(method_name, optmanager, *args, **kwargs):
def generated_function(plugin):
+ """Function that attempts to call a specific method on a plugin."""
method = getattr(plugin, method_name, None)
if (method is not None and
isinstance(method, collections.Callable)):
@@ -244,6 +247,7 @@ class PluginTypeManager(object):
return
def load_plugin(plugin):
+ """Call each plugin's load_plugin method."""
return plugin.load_plugin()
plugins = list(self.manager.map(load_plugin))
@@ -269,7 +273,7 @@ class PluginTypeManager(object):
list(self.manager.map(call_provide_options))
-class NotifierBuilder(object):
+class NotifierBuilderMixin(object): # pylint: disable=too-few-public-methods
"""Mixin class that builds a Notifier from a PluginManager."""
def build_notifier(self):
@@ -293,7 +297,7 @@ class Checkers(PluginTypeManager):
namespace = 'flake8.extension'
-class Listeners(PluginTypeManager, NotifierBuilder):
+class Listeners(PluginTypeManager, NotifierBuilderMixin):
"""All of the listeners registered through entry-points."""
namespace = 'flake8.listen'
diff --git a/flake8/plugins/pyflakes.py b/flake8/plugins/pyflakes.py
index 7f6107a..f512511 100644
--- a/flake8/plugins/pyflakes.py
+++ b/flake8/plugins/pyflakes.py
@@ -23,7 +23,7 @@ def patch_pyflakes():
'F402 ImportShadowedByLoopVar',
'F403 ImportStarUsed',
'F404 LateFutureImport',
- 'F810 Redefined', # XXX Obsolete?
+ 'F810 Redefined',
'F811 RedefinedWhileUnused',
'F812 RedefinedInListComp',
'F821 UndefinedName',
@@ -48,23 +48,23 @@ class FlakesChecker(pyflakes.checker.Checker):
def __init__(self, tree, filename):
"""Initialize the PyFlakes plugin with an AST tree and filename."""
filename = utils.normalize_paths(filename)[0]
- withDoctest = self.withDoctest
+ with_doctest = self.with_doctest
included_by = [include for include in self.include_in_doctest
if include != '' and filename.startswith(include)]
if included_by:
- withDoctest = True
+ with_doctest = True
for exclude in self.exclude_from_doctest:
if exclude != '' and filename.startswith(exclude):
- withDoctest = False
+ with_doctest = False
overlaped_by = [include for include in included_by
if include.startswith(exclude)]
if overlaped_by:
- withDoctest = True
+ with_doctest = True
super(FlakesChecker, self).__init__(tree, filename,
- withDoctest=withDoctest)
+ withDoctest=with_doctest)
@classmethod
def add_options(cls, parser):
@@ -98,7 +98,7 @@ class FlakesChecker(pyflakes.checker.Checker):
"""Parse option values from Flake8's OptionManager."""
if options.builtins:
cls.builtIns = cls.builtIns.union(options.builtins)
- cls.withDoctest = options.doctests
+ cls.with_doctest = options.doctests
included_files = []
for included_file in options.include_in_doctest:
@@ -131,6 +131,9 @@ class FlakesChecker(pyflakes.checker.Checker):
def run(self):
"""Run the plugin."""
- for m in self.messages:
- col = getattr(m, 'col', 0)
- yield m.lineno, col, (m.flake8_msg % m.message_args), m.__class__
+ for message in self.messages:
+ col = getattr(message, 'col', 0)
+ yield (message.lineno,
+ col,
+ (message.flake8_msg % message.message_args),
+ message.__class__)
diff --git a/flake8/style_guide.py b/flake8/style_guide.py
index 6a05249..00a46fe 100644
--- a/flake8/style_guide.py
+++ b/flake8/style_guide.py
@@ -145,15 +145,15 @@ class StyleGuide(object):
code, selected, ignored)
if ((selected is Selected.Explicitly or
- selected is Selected.Implicitly) and
+ selected is Selected.Implicitly) and
ignored is Selected.Implicitly):
decision = Decision.Selected
elif (selected is Selected.Explicitly and
- ignored is Ignored.Explicitly):
+ ignored is Ignored.Explicitly):
decision = self._decision_for(code)
elif (selected is Ignored.Implicitly or
- ignored is Ignored.Explicitly):
- decision = Decision.Ignored
+ ignored is Ignored.Explicitly):
+ decision = Decision.Ignored # pylint: disable=R0204
self._decision_cache[code] = decision
LOG.debug('"%s" will be "%s"', code, decision)
diff --git a/flake8/utils.py b/flake8/utils.py
index 98e5cea..1165470 100644
--- a/flake8/utils.py
+++ b/flake8/utils.py
@@ -33,7 +33,8 @@ def normalize_paths(paths, parent=os.curdir):
:rtype:
[str]
"""
- return [normalize_path(p) for p in parse_comma_separated_list(paths)]
+ return [normalize_path(p, parent)
+ for p in parse_comma_separated_list(paths)]
def normalize_path(path, parent=os.curdir):
@@ -57,8 +58,8 @@ def stdin_get_value():
if cached_value is None:
stdin_value = sys.stdin.read()
if sys.version_info < (3, 0):
- cached_value = io.BytesIO(stdin_value)
+ cached_type = io.BytesIO
else:
- cached_value = io.StringIO(stdin_value)
- stdin_get_value.cached_stdin = cached_value
+ cached_type = io.StringIO
+ stdin_get_value.cached_stdin = cached_type(stdin_value)
return cached_value.getvalue()
diff --git a/tests/unit/test_config_file_finder.py b/tests/unit/test_config_file_finder.py
index 200f4e5..6ac1d16 100644
--- a/tests/unit/test_config_file_finder.py
+++ b/tests/unit/test_config_file_finder.py
@@ -68,11 +68,11 @@ def test_cli_config():
os.path.abspath('tox.ini'),
os.path.abspath('.flake8')]),
])
-def test_generate_possible_local_config_files(args, expected):
+def test_generate_possible_local_files(args, expected):
"""Verify generation of all possible config paths."""
finder = config.ConfigFileFinder('flake8', args, [])
- assert (list(finder.generate_possible_local_config_files()) ==
+ assert (list(finder.generate_possible_local_files()) ==
expected)