summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--gui.py6
-rw-r--r--interfaces.py41
-rw-r--r--lint.py4
-rw-r--r--pyreverse/diadefslib.py18
-rw-r--r--pyreverse/utils.py4
-rw-r--r--pyreverse/writer.py21
-rw-r--r--reporters/__init__.py1
-rw-r--r--reporters/guireporter.py4
-rw-r--r--reporters/text.py27
-rw-r--r--testutils.py4
-rw-r--r--utils.py16
22 files changed, 111 insertions, 150 deletions
diff --git a/checkers/__init__.py b/checkers/__init__.py
index ff9d421..27dc364 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 4b3b3c9..bb6f778 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 00b1e44..eb82d0d 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 3286e48..69ed2e5 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 ca88c8b..6995909 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 3b99b28..9832195 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 dc4ad7e..a8e4367 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 79fcd9d..26b3725 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 89261eb..07e1fbe 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 6a4ab7b..42563da 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 ea297e5..7e924ef 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
diff --git a/gui.py b/gui.py
index e4fb9a8..79a4089 100644
--- a/gui.py
+++ b/gui.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2003-2012 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
@@ -23,7 +23,7 @@ from threading import Thread
from Tkinter import (Tk, Frame, Listbox, Entry, Label, Button, Scrollbar,
Checkbutton, Radiobutton, IntVar, StringVar)
from Tkinter import (TOP, LEFT, RIGHT, BOTTOM, END, X, Y, BOTH, SUNKEN, W,
- HORIZONTAL, DISABLED, NORMAL, W, E)
+ HORIZONTAL, DISABLED, NORMAL, W)
from tkFileDialog import askopenfilename, askdirectory
import pylint.lint
@@ -86,7 +86,7 @@ class BasicStream(object):
"""finalize what the contents of the dict should look like before output"""
for item in self.outdict:
numEmpty = self.outdict[item].count('')
- for i in xrange(numEmpty):
+ for _ in xrange(numEmpty):
self.outdict[item].remove('')
if self.outdict[item]:
self.outdict[item].pop(0)
diff --git a/interfaces.py b/interfaces.py
index f3f7591..e0754ce 100644
--- a/interfaces.py
+++ b/interfaces.py
@@ -10,13 +10,7 @@
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-""" Copyright (c) 2002-2003 LOGILAB S.A. (Paris, FRANCE).
- http://www.logilab.fr/ -- mailto:contact@logilab.fr
-
-Interfaces for PyLint objects
-"""
-
-__revision__ = "$Id: interfaces.py,v 1.9 2004-04-24 12:14:53 syt Exp $"
+"""Interfaces for PyLint objects"""
from logilab.common.interface import Interface
@@ -32,12 +26,6 @@ class IChecker(Interface):
def close(self):
"""called after visiting project (i.e set of modules)"""
-## def open_module(self):
-## """called before visiting a module"""
-
-## def close_module(self):
-## """called after visiting a module"""
-
class IRawChecker(IChecker):
"""interface for checker which need to parse the raw file
@@ -54,7 +42,7 @@ class ITokenChecker(IChecker):
"""Interface for checkers that need access to the token list."""
def process_tokens(self, tokens):
"""Process a module.
-
+
tokens is a list of all source code tokens in the file.
"""
@@ -65,29 +53,6 @@ class IAstroidChecker(IChecker):
"""
-class ILinter(Interface):
- """interface for the linter class
-
- the linter class will generate events to its registered checkers.
- Each checker may interact with the linter instance using this API
- """
-
- def register_checker(self, checker):
- """register a new checker class
-
- checker is a class implementing IrawChecker or / and IAstroidChecker
- """
-
- def add_message(self, msg_id, line=None, node=None, args=None):
- """add the message corresponding to the given id.
-
- If provided, msg is expanded using args
-
- astroid checkers should provide the node argument,
- raw checkers should provide the line argument.
- """
-
-
class IReporter(Interface):
""" reporter collect messages and display results encapsulated in a layout
"""
@@ -104,4 +69,4 @@ class IReporter(Interface):
"""
-__all__ = ('IRawChecker', 'ILinter', 'IReporter')
+__all__ = ('IRawChecker', 'IAstroidChecker', 'ITokenChecker', 'IReporter')
diff --git a/lint.py b/lint.py
index e5a66fd..a039bae 100644
--- a/lint.py
+++ b/lint.py
@@ -50,7 +50,7 @@ from pylint.utils import (
PyLintASTWalker, UnknownMessage, MessagesHandlerMixIn, ReportsHandlerMixIn,
EmptyReport, WarningScope,
expand_modules, tokenize_module)
-from pylint.interfaces import ILinter, IRawChecker, ITokenChecker, IAstroidChecker
+from pylint.interfaces import IRawChecker, ITokenChecker, IAstroidChecker
from pylint.checkers import (BaseTokenChecker,
table_lines_from_stats,
initialize as checkers_initialize)
@@ -164,7 +164,7 @@ class PyLinter(OptionsManagerMixIn, MessagesHandlerMixIn, ReportsHandlerMixIn,
to ensure the latest code version is actually checked.
"""
- __implements__ = (ILinter, ITokenChecker)
+ __implements__ = (ITokenChecker,)
name = 'master'
priority = 0
diff --git a/pyreverse/diadefslib.py b/pyreverse/diadefslib.py
index ebdf095..da21e1f 100644
--- a/pyreverse/diadefslib.py
+++ b/pyreverse/diadefslib.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2000-2010 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2000-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
@@ -17,17 +17,19 @@
"""
from logilab.common.compat import builtins
-BUILTINS_NAME = builtins.__name__
+
import astroid
from astroid.utils import LocalsVisitor
from pylint.pyreverse.diagrams import PackageDiagram, ClassDiagram
+BUILTINS_NAME = builtins.__name__
+
# diagram generators ##########################################################
-class DiaDefGenerator:
- """handle diagram generation options
- """
+class DiaDefGenerator(object):
+ """handle diagram generation options"""
+
def __init__(self, linker, handler):
"""common Diagram Handler initialization"""
self.config = handler.config
@@ -102,7 +104,7 @@ class DiaDefGenerator:
for ass_node in ass_nodes:
if isinstance(ass_node, astroid.Instance):
ass_node = ass_node._proxied
- if not (isinstance(ass_node, astroid.Class)
+ if not (isinstance(ass_node, astroid.Class)
and self.show_node(ass_node)):
continue
yield ass_node
@@ -204,7 +206,7 @@ class ClassDiadefGenerator(DiaDefGenerator):
# diagram handler #############################################################
-class DiadefsHandler:
+class DiadefsHandler(object):
"""handle diagram definitions :
get it from user (i.e. xml files) or generate them
@@ -216,7 +218,7 @@ class DiadefsHandler:
def get_diadefs(self, project, linker):
"""get the diagrams configuration data
:param linker: astroid.inspector.Linker(IdGeneratorMixIn, LocalsVisitor)
- :param project: astroid.manager.Project
+ :param project: astroid.manager.Project
"""
# read and interpret diagram definitions (Diadefs)
diff --git a/pyreverse/utils.py b/pyreverse/utils.py
index 58263b6..976f704 100644
--- a/pyreverse/utils.py
+++ b/pyreverse/utils.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2002-2010 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2002-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
@@ -109,7 +109,7 @@ MODES = {
VIS_MOD = {'special': _SPECIAL, 'protected': _PROTECTED, \
'private': _PRIVATE, 'public': 0 }
-class FilterMixIn:
+class FilterMixIn(object):
"""filter nodes according to a mode and nodes' visibility
"""
def __init__(self, mode):
diff --git a/pyreverse/writer.py b/pyreverse/writer.py
index 6dbfc26..940e324 100644
--- a/pyreverse/writer.py
+++ b/pyreverse/writer.py
@@ -1,5 +1,4 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2008-2010 LOGILAB S.A. (Paris, FRANCE).
+# Copyright (c) 2008-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
@@ -14,16 +13,14 @@
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-"""
-Utilities for creating VCG and Dot diagrams.
-"""
+"""Utilities for creating VCG and Dot diagrams"""
from logilab.common.vcgutils import VCGPrinter
from logilab.common.graph import DotBackend
from pylint.pyreverse.utils import is_exception
-class DiagramWriter:
+class DiagramWriter(object):
"""base class for writing project diagrams
"""
def __init__(self, config, styles):
@@ -93,8 +90,8 @@ class DotWriter(DiagramWriter):
"""
def __init__(self, config):
- styles = [dict(arrowtail='none', arrowhead="open"),
- dict(arrowtail = "none", arrowhead='empty'),
+ styles = [dict(arrowtail='none', arrowhead="open"),
+ dict(arrowtail = "none", arrowhead='empty'),
dict(arrowtail="node", arrowhead='empty', style='dashed'),
dict(fontcolor='green', arrowtail='none',
arrowhead='diamond', style='solid') ]
@@ -113,14 +110,14 @@ class DotWriter(DiagramWriter):
def get_values(self, obj):
"""get label and shape for classes.
-
+
The label contains all attributes and methods
"""
label = obj.title
if obj.shape == 'interface':
label = "«interface»\\n%s" % label
if not self.config.only_classnames:
- label = "%s|%s\l|" % (label, r"\l".join(obj.attrs) )
+ label = r"%s|%s\l|" % (label, r"\l".join(obj.attrs) )
for func in obj.methods:
label = r'%s%s()\l' % (label, func.name)
label = '{%s}' % label
@@ -139,7 +136,7 @@ class VCGWriter(DiagramWriter):
def __init__(self, config):
styles = [dict(arrowstyle='solid', backarrowstyle='none',
backarrowsize=0),
- dict(arrowstyle='solid', backarrowstyle='none',
+ dict(arrowstyle='solid', backarrowstyle='none',
backarrowsize=10),
dict(arrowstyle='solid', backarrowstyle='none',
linestyle='dotted', backarrowsize=10),
@@ -163,7 +160,7 @@ class VCGWriter(DiagramWriter):
def get_values(self, obj):
"""get label and shape for classes.
-
+
The label contains all attributes and methods
"""
if is_exception(obj.node):
diff --git a/reporters/__init__.py b/reporters/__init__.py
index 0b80c4e..53064c7 100644
--- a/reporters/__init__.py
+++ b/reporters/__init__.py
@@ -73,6 +73,7 @@ class BaseReporter(object):
self.section = 0
self.out = None
self.out_encoding = None
+ self.encode = None
self.set_output(output)
# Build the path prefix to strip to get relative paths
self.path_strip_prefix = os.getcwd() + os.sep
diff --git a/reporters/guireporter.py b/reporters/guireporter.py
index 83cc049..9f3ae79 100644
--- a/reporters/guireporter.py
+++ b/reporters/guireporter.py
@@ -22,8 +22,8 @@ class GUIReporter(BaseReporter):
def add_message(self, msg_id, location, msg):
"""manage message of different type and in the context of path"""
filename, module, obj, line, col_offset = location
- sigle = self.make_sigle(msg_id)
- full_msg = [sigle, msg_id, filename, module, obj, str(line), msg]
+ msg = Message(self, msg_id, location, msg)
+ full_msg = [msg.C, msg_id, filename, module, obj, str(line), msg]
self.msgs += [[sigle, module, obj, str(line)]]
self.gui.msg_queue.put(full_msg)
diff --git a/reporters/text.py b/reporters/text.py
index b024a0f..657ffd8 100644
--- a/reporters/text.py
+++ b/reporters/text.py
@@ -17,7 +17,6 @@
:colorized: an ANSI colorized text reporter
"""
-import os.path as osp
import warnings
from logilab.common.ureports import TextWriter
@@ -45,9 +44,9 @@ class TextReporter(BaseReporter):
def on_set_current_module(self, module, filepath):
self._template = unicode(self.linter.config.msg_template or self.line_format)
- def write_message(self, m, template=None):
+ def write_message(self, msg):
"""Convenience method to write a formated message with class default template"""
- self.writeln(m.format(self._template))
+ self.writeln(msg.format(self._template))
def add_message(self, msg_id, location, msg):
"""manage message of different type and in the context of path"""
@@ -75,9 +74,9 @@ class ParseableTextReporter(TextReporter):
name = 'parseable'
line_format = '{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'
- def __init__(self, output=None, relative=True):
+ def __init__(self, output=None):
warnings.warn('%s output format is deprecated. This is equivalent to --msg-template=%s'
- % (self.name, self.line_format))
+ % (self.name, self.line_format))
TextReporter.__init__(self, output)
@@ -119,21 +118,21 @@ class ColorizedTextReporter(TextReporter):
"""manage message of different types, and colorize output
using ansi escape codes
"""
- m = Message(self, msg_id, location, msg)
- if m.module not in self._modules:
+ msg = Message(self, msg_id, location, msg)
+ if msg.module not in self._modules:
color, style = self._get_decoration('S')
- if m.module:
- modsep = colorize_ansi('************* Module %s' % m.module,
+ if msg.module:
+ modsep = colorize_ansi('************* Module %s' % msg.module,
color, style)
else:
- modsep = colorize_ansi('************* %s' % m.module,
+ modsep = colorize_ansi('************* %s' % msg.module,
color, style)
self.writeln(modsep)
- self._modules[m.module] = 1
- color, style = self._get_decoration(m.C)
+ self._modules[msg.module] = 1
+ color, style = self._get_decoration(msg.C)
for attr in ('msg', 'symbol', 'category', 'C'):
- setattr(m, attr, colorize_ansi(getattr(m, attr), color, style))
- self.write_message(m)
+ setattr(msg, attr, colorize_ansi(getattr(msg, attr), color, style))
+ self.write_message(msg)
def register(linter):
diff --git a/testutils.py b/testutils.py
index c3f719f..e939e51 100644
--- a/testutils.py
+++ b/testutils.py
@@ -134,7 +134,7 @@ class UnittestLinter(object):
def add_message(self, msg_id, line=None, node=None, args=None):
self._messages.append(Message(msg_id, line, node, args))
-
+
def is_message_enabled(self, *unused_args):
return True
@@ -161,7 +161,7 @@ class CheckerTestCase(testlib.TestCase):
"""Assert that no messages are added by the given method."""
with self.assertAddsMessages():
yield
-
+
@contextlib.contextmanager
def assertAddsMessages(self, *messages):
"""Assert that exactly the given method adds the given messages.
diff --git a/utils.py b/utils.py
index 65f9669..1895a75 100644
--- a/utils.py
+++ b/utils.py
@@ -277,8 +277,8 @@ class MessagesHandlerMixIn(object):
# msgid is a checker name?
if msgid.lower() in self._checkers:
for checker in self._checkers[msgid.lower()]:
- for msgid in checker.msgs:
- self.enable(msgid, scope, line)
+ for msgid_ in checker.msgs:
+ self.enable(msgid_, scope, line)
return
# msgid is report id?
if msgid.lower().startswith('rp'):
@@ -490,7 +490,7 @@ class MessagesHandlerMixIn(object):
print
-class ReportsHandlerMixIn:
+class ReportsHandlerMixIn(object):
"""a mix-in class containing all the reports and stats manipulation
related methods for the main lint class
"""
@@ -672,11 +672,11 @@ def register_plugins(linter, directory):
"""
imported = {}
for filename in os.listdir(directory):
- basename, extension = splitext(filename)
- if basename in imported or basename == '__pycache__':
+ base, extension = splitext(filename)
+ if base in imported or base == '__pycache__':
continue
- if extension in PY_EXTS and basename != '__init__' or (
- not extension and isdir(join(directory, basename))):
+ if extension in PY_EXTS and base != '__init__' or (
+ not extension and isdir(join(directory, base))):
try:
module = load_module_from_file(join(directory, filename))
except ValueError:
@@ -687,5 +687,5 @@ def register_plugins(linter, directory):
else:
if hasattr(module, 'register'):
module.register(linter)
- imported[basename] = 1
+ imported[base] = 1