summaryrefslogtreecommitdiff
path: root/checkers
diff options
context:
space:
mode:
Diffstat (limited to 'checkers')
-rw-r--r--checkers/__init__.py3
-rw-r--r--checkers/base.py18
-rw-r--r--checkers/exceptions.py14
-rw-r--r--checkers/format.py2
-rw-r--r--checkers/misc.py4
-rw-r--r--checkers/newstyle.py10
-rw-r--r--checkers/raw_metrics.py12
-rw-r--r--checkers/similar.py7
-rw-r--r--checkers/stdlib.py2
-rw-r--r--checkers/strings.py2
-rw-r--r--checkers/variables.py41
11 files changed, 56 insertions, 59 deletions
diff --git a/checkers/__init__.py b/checkers/__init__.py
index ff9d421a1..27dc36459 100644
--- a/checkers/__init__.py
+++ b/checkers/__init__.py
@@ -38,6 +38,7 @@ messages nor reports. XXX not true, emit a 07 report !
"""
+import sys
import tokenize
import warnings
from os.path import dirname
@@ -138,7 +139,7 @@ class BaseRawChecker(BaseChecker):
class BaseTokenChecker(BaseChecker):
"""Base class for checkers that want to have access to the token stream."""
-
+
def process_tokens(self, tokens):
"""Should be overridden by subclasses."""
raise NotImplementedError()
diff --git a/checkers/base.py b/checkers/base.py
index 4b3b3c959..bb6f77837 100644
--- a/checkers/base.py
+++ b/checkers/base.py
@@ -105,7 +105,7 @@ def _determine_function_name_type(node):
(isinstance(decorator, astroid.Getattr) and
decorator.attrname == 'abstractproperty')):
infered = safe_infer(decorator)
- if (infered and
+ if (infered and
infered.qname() in ('__builtin__.property', 'abc.abstractproperty')):
return 'attr'
# If the function is decorated using the prop_method.{setter,getter}
@@ -220,7 +220,7 @@ class BasicErrorChecker(_BasicChecker):
'with a break statement, otherwise the statements under else '
'should be on the same scope as the loop itself.'),
}
-
+
def __init__(self, linter):
_BasicChecker.__init__(self, linter)
@@ -228,8 +228,8 @@ class BasicErrorChecker(_BasicChecker):
def visit_class(self, node):
self._check_redefinition('class', node)
- @check_messages('init-is-generator', 'return-in-init',
- 'function-redefined', 'return-arg-in-generator',
+ @check_messages('init-is-generator', 'return-in-init',
+ 'function-redefined', 'return-arg-in-generator',
'duplicate-argument-name')
def visit_function(self, node):
if not redefined_by_decorator(node):
@@ -243,8 +243,8 @@ class BasicErrorChecker(_BasicChecker):
else:
values = [r.value for r in returns]
# Are we returning anything but None from constructors
- if [v for v in values if
- not (v is None or
+ if [v for v in values if
+ not (v is None or
(isinstance(v, astroid.Const) and v.value is None) or
(isinstance(v, astroid.Name) and v.name == 'None')
) ]:
@@ -257,7 +257,7 @@ class BasicErrorChecker(_BasicChecker):
self.add_message('return-arg-in-generator', node=node,
line=retnode.fromlineno)
# Check for duplicate names
- args = set()
+ args = set()
for name in node.argnames():
if name in args:
self.add_message('duplicate-argument-name', node=node, args=(name,))
@@ -454,7 +454,7 @@ functions, methods
"""
self.stats['class'] += 1
- @check_messages('pointless-statement', 'pointless-string-statement',
+ @check_messages('pointless-statement', 'pointless-string-statement',
'expression-not-assigned')
def visit_discard(self, node):
"""check for various kind of statements without effect"""
@@ -883,7 +883,7 @@ class DocStringChecker(_BasicChecker):
' require docstrings, shorter ones are exempt.')}
),
)
-
+
def open(self):
self.stats = self.linter.add_stats(undocumented_module=0,
diff --git a/checkers/exceptions.py b/checkers/exceptions.py
index 00b1e4478..eb82d0dff 100644
--- a/checkers/exceptions.py
+++ b/checkers/exceptions.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2003-2007 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
@@ -46,7 +46,7 @@ MSGS = {
'notimplemented-raised',
'Used when NotImplemented is raised instead of \
NotImplementedError'),
-
+
'W0701': ('Raising a string exception',
'raising-string',
'Used when a string exception is raised.'),
@@ -86,11 +86,11 @@ else:
EXCEPTIONS_MODULE = "builtins"
class ExceptionsChecker(BaseChecker):
- """checks for
- * excepts without exception filter
+ """checks for
+ * excepts without exception filter
* type of raise argument : string, Exceptions, other values
"""
-
+
__implements__ = IAstroidChecker
name = 'exceptions'
@@ -134,7 +134,7 @@ class ExceptionsChecker(BaseChecker):
args=value.__class__.__name__)
elif (isinstance(expr, astroid.Name) and \
expr.name in ('None', 'True', 'False')) or \
- isinstance(expr, (astroid.List, astroid.Dict, astroid.Tuple,
+ isinstance(expr, (astroid.List, astroid.Dict, astroid.Tuple,
astroid.Module, astroid.Function)):
self.add_message('E0702', node=node, args=expr.name)
elif ( (isinstance(expr, astroid.Name) and expr.name == 'NotImplemented')
@@ -192,7 +192,7 @@ class ExceptionsChecker(BaseChecker):
except astroid.InferenceError:
continue
for exc in excs:
- # XXX skip other non class nodes
+ # XXX skip other non class nodes
if exc is YES or not isinstance(exc, astroid.Class):
continue
exc_ancestors = [anc for anc in exc.ancestors()
diff --git a/checkers/format.py b/checkers/format.py
index 3286e4862..69ed2e5e1 100644
--- a/checkers/format.py
+++ b/checkers/format.py
@@ -352,7 +352,7 @@ class FormatChecker(BaseTokenChecker):
for line in lines.splitlines(True):
if not line.endswith('\n'):
- self.add_message('C0304', line=i)
+ self.add_message('C0304', line=i)
else:
stripped_line = line.rstrip()
if line != stripped_line + '\n':
diff --git a/checkers/misc.py b/checkers/misc.py
index ca88c8ba3..69959090c 100644
--- a/checkers/misc.py
+++ b/checkers/misc.py
@@ -62,9 +62,9 @@ separated by a comma.'
def _check_encoding(self, lineno, line, file_encoding):
try:
return unicode(line, file_encoding)
- except UnicodeDecodeError, e:
+ except UnicodeDecodeError, ex:
self.add_message('W0512', line=lineno,
- args=(file_encoding, e.args[2]))
+ args=(file_encoding, ex.args[2]))
def process_module(self, module):
"""inspect the source file to find encoding problem or fixmes like
diff --git a/checkers/newstyle.py b/checkers/newstyle.py
index 3b99b2892..98321954a 100644
--- a/checkers/newstyle.py
+++ b/checkers/newstyle.py
@@ -52,11 +52,11 @@ MSGS = {
class NewStyleConflictChecker(BaseChecker):
"""checks for usage of new style capabilities on old style classes and
- other new/old styles conflicts problems
- * use of property, __slots__, super
- * "super" usage
+ other new/old styles conflicts problems
+ * use of property, __slots__, super
+ * "super" usage
"""
-
+
__implements__ = (IAstroidChecker,)
# configuration section name
@@ -70,7 +70,7 @@ class NewStyleConflictChecker(BaseChecker):
@check_messages('E1001', 'C1001')
def visit_class(self, node):
"""check __slots__ usage
- """
+ """
if '__slots__' in node and not node.newstyle:
self.add_message('E1001', node=node)
# The node type could be class, exception, metaclass, or
diff --git a/checkers/raw_metrics.py b/checkers/raw_metrics.py
index dc4ad7ee3..a8e4367ce 100644
--- a/checkers/raw_metrics.py
+++ b/checkers/raw_metrics.py
@@ -55,12 +55,12 @@ def report_raw_stats(sect, stats, old_stats):
class RawMetricsChecker(BaseTokenChecker):
- """does not check anything but gives some raw metrics :
- * total number of lines
- * total number of code lines
- * total number of docstring lines
- * total number of comments lines
- * total number of empty lines
+ """does not check anything but gives some raw metrics :
+ * total number of lines
+ * total number of code lines
+ * total number of docstring lines
+ * total number of comments lines
+ * total number of empty lines
"""
__implements__ = (ITokenChecker,)
diff --git a/checkers/similar.py b/checkers/similar.py
index 79fcd9d10..26b372558 100644
--- a/checkers/similar.py
+++ b/checkers/similar.py
@@ -1,5 +1,5 @@
# pylint: disable=W0622
-# Copyright (c) 2004-2012 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2004-2013 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
@@ -25,7 +25,7 @@ from pylint.interfaces import IRawChecker
from pylint.checkers import BaseChecker, table_lines_from_stats
-class Similar:
+class Similar(object):
"""finds copy-pasted lines of code in a project"""
def __init__(self, min_lines=4, ignore_comments=False,
@@ -160,7 +160,8 @@ def stripped_lines(lines, ignore_comments, ignore_docstrings, ignore_imports):
strippedlines.append(line)
return strippedlines
-class LineSet:
+
+class LineSet(object):
"""Holds and indexes all the lines of a single source file"""
def __init__(self, name, lines, ignore_comments=False,
ignore_docstrings=False, ignore_imports=False):
diff --git a/checkers/stdlib.py b/checkers/stdlib.py
index 89261eb17..07e1fbe18 100644
--- a/checkers/stdlib.py
+++ b/checkers/stdlib.py
@@ -20,7 +20,7 @@ import sys
import astroid
-from pylint.interfaces import ITokenChecker, IAstroidChecker
+from pylint.interfaces import IAstroidChecker
from pylint.checkers import BaseChecker, BaseTokenChecker
from pylint.checkers import utils
diff --git a/checkers/strings.py b/checkers/strings.py
index 6a4ab7bf0..42563da77 100644
--- a/checkers/strings.py
+++ b/checkers/strings.py
@@ -85,7 +85,7 @@ class StringFormatChecker(BaseChecker):
__implements__ = (IAstroidChecker,)
name = 'string'
msgs = MSGS
-
+
@check_messages(*(MSGS.keys()))
def visit_binop(self, node):
if node.op != '%':
diff --git a/checkers/variables.py b/checkers/variables.py
index ea297e5a7..7e924ef4a 100644
--- a/checkers/variables.py
+++ b/checkers/variables.py
@@ -544,29 +544,24 @@ builtins. Remember that you should avoid to define new builtins when possible.'
@check_messages('unbalanced-tuple-unpacking')
def visit_assign(self, node):
- """ Check unbalanced tuple unpacking for assignments. """
- if not isinstance(node.targets[0], (astroid.Tuple, astroid.List)):
- return
-
- try:
- infered = node.value.infer().next()
- except astroid.InferenceError:
- return
-
- if not isinstance(infered, (astroid.Tuple, astroid.List)):
- return
-
- targets = node.targets[0].itered()
- values = infered.itered()
-
- if any(not isinstance(target_node, astroid.AssName)
- for target_node in targets):
- return
-
- if len(targets) != len(values):
- self.add_message('unbalanced-tuple-unpacking',
- node=node,
- args=(len(targets), len(values)))
+ """Check unbalanced tuple unpacking for assignments"""
+ if not isinstance(node.targets[0], (astroid.Tuple, astroid.List)):
+ return
+ try:
+ infered = node.value.infer().next()
+ except astroid.InferenceError:
+ return
+ if not isinstance(infered, (astroid.Tuple, astroid.List)):
+ return
+ targets = node.targets[0].itered()
+ values = infered.itered()
+ if any(not isinstance(target_node, astroid.AssName)
+ for target_node in targets):
+ return
+ if len(targets) != len(values):
+ self.add_message('unbalanced-tuple-unpacking',
+ node=node,
+ args=(len(targets), len(values)))
def _check_module_attrs(self, node, module, module_names):
"""check that module_names (list of string) are accessible through the