diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2012-09-19 17:36:47 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2012-09-19 17:36:47 +0200 |
commit | d4d8fe742e8860df3a699a4999be133a1fc8db42 (patch) | |
tree | 0d616ccb2d84a926c1dba1f67c4181a3956cd27f | |
parent | fcc1a91b50f564627716230ffc159381b241c07f (diff) | |
download | pylint-d4d8fe742e8860df3a699a4999be133a1fc8db42.tar.gz |
lint fixes
-rw-r--r-- | checkers/base.py | 4 | ||||
-rw-r--r-- | checkers/format.py | 2 | ||||
-rw-r--r-- | checkers/imports.py | 2 | ||||
-rw-r--r-- | checkers/string_format.py | 2 | ||||
-rw-r--r-- | checkers/typecheck.py | 4 | ||||
-rw-r--r-- | checkers/variables.py | 6 | ||||
-rw-r--r-- | gui.py | 32 | ||||
-rw-r--r-- | interfaces.py | 2 | ||||
-rw-r--r-- | lint.py | 14 | ||||
-rw-r--r-- | reporters/text.py | 1 | ||||
-rw-r--r-- | test/utils.py | 5 | ||||
-rw-r--r-- | testutils.py | 17 | ||||
-rw-r--r-- | utils.py | 9 |
13 files changed, 50 insertions, 50 deletions
diff --git a/checkers/base.py b/checkers/base.py index 08ea0cc..69b0a2b 100644 --- a/checkers/base.py +++ b/checkers/base.py @@ -529,13 +529,13 @@ functions, methods """check the use of an assert statement on a tuple.""" if node.fail is None and isinstance(node.test, astng.Tuple) and \ len(node.test.elts) == 2: - self.add_message('W0199', line=node.fromlineno, node=node) + self.add_message('W0199', line=node.fromlineno, node=node) @check_messages('W0109') def visit_dict(self, node): """check duplicate key in dictionary""" keys = set() - for k, v in node.items: + for k, _ in node.items: if isinstance(k, astng.Const): key = k.value if key in keys: diff --git a/checkers/format.py b/checkers/format.py index 67b6952..d45667f 100644 --- a/checkers/format.py +++ b/checkers/format.py @@ -421,7 +421,7 @@ class StringConstantChecker(BaseRawChecker): start_row, start_col) def process_non_raw_string_token(self, prefix, string_body, start_row, - start_col): + start_col): """check for bad escapes in a non-raw string. prefix: lowercase string of eg 'ur' string prefix markers. diff --git a/checkers/imports.py b/checkers/imports.py index 2b61cf4..5939a2a 100644 --- a/checkers/imports.py +++ b/checkers/imports.py @@ -86,7 +86,7 @@ def repr_tree_defs(data, indent_str=None): lines.append('%s %s' % (mod, files)) sub_indent_str = ' ' else: - lines.append('%s\-%s %s' % (indent_str, mod, files)) + lines.append(r'%s\-%s %s' % (indent_str, mod, files)) if i == len(nodes)-1: sub_indent_str = '%s ' % indent_str else: diff --git a/checkers/string_format.py b/checkers/string_format.py index d21ad3e..0384f03 100644 --- a/checkers/string_format.py +++ b/checkers/string_format.py @@ -110,7 +110,7 @@ class StringFormatChecker(BaseChecker): if isinstance(args, astng.Dict): keys = set() unknown_keys = False - for k, v in args.items: + for k, _ in args.items: if isinstance(k, astng.Const): key = k.value if isinstance(key, basestring): diff --git a/checkers/typecheck.py b/checkers/typecheck.py index 23bb7aa..95289f0 100644 --- a/checkers/typecheck.py +++ b/checkers/typecheck.py @@ -182,7 +182,7 @@ accessed. Python regular expressions are accepted.'} continue except NotFoundError: if isinstance(owner, astng.Function) and owner.decorators: - continue + continue if isinstance(owner, Instance) and owner.has_dynamic_getattr(): continue # explicit skipping of optparse'Values class @@ -377,7 +377,7 @@ accessed. Python regular expressions are accepted.'} for [(name, defval), assigned] in parameters: if (defval is None) and not assigned: if name is None: - display = '<tuple>' + display_name = '<tuple>' else: display_name = repr(name) self.add_message('E1120', node=node, args=display_name) diff --git a/checkers/variables.py b/checkers/variables.py index e3812fc..01ea6f8 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -31,9 +31,9 @@ from pylint.checkers.utils import (PYMETHODS, is_ancestor_name, is_builtin, def in_for_else_branch(parent, stmt): - """Returns True if stmt in inside the else branch for a parent For stmt.""" - return (isinstance(parent, astng.For) and - any(else_stmt.parent_of(stmt) for else_stmt in parent.orelse)) + """Returns True if stmt in inside the else branch for a parent For stmt.""" + return (isinstance(parent, astng.For) and + any(else_stmt.parent_of(stmt) for else_stmt in parent.orelse)) def overridden_method(klass, name): """get overridden method if any""" @@ -36,6 +36,14 @@ COLORS = {'(I)':'lightblue', '(W)':'black', '(E)':'darkred', '(F)':'red'} + +def convert_to_string(msg): + """make a string representation of a message""" + if (msg[2] != ""): + return "(" + msg[0] + ") " + msg[1] + "." + msg[2] + " [" + msg[3] + "]: " + msg[4] + else: + return "(" + msg[0] + ") " + msg[1] + " [" + msg[3] + "]: " + msg[4] + class BasicStream: ''' used in gui reporter instead of writing to stdout, it is written to @@ -64,18 +72,21 @@ class BasicStream: if text.startswith('\n'): self.contents.append('') - if self.currout: self.outdict[self.currout].append('') + if self.currout: + self.outdict[self.currout].append('') self.contents[-1] += text.strip('\n') - if self.currout: self.outdict[self.currout][-1] += text.strip('\n') + if self.currout: + self.outdict[self.currout][-1] += text.strip('\n') if text.endswith('\n') and text.strip(): self.contents.append('') - if self.currout: self.outdict[self.currout].append('') + if self.currout: + self.outdict[self.currout].append('') def fix_contents(self): """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 range(numEmpty): + for i in xrange(numEmpty): self.outdict[item].remove('') if self.outdict[item]: self.outdict[item].pop(0) @@ -308,7 +319,7 @@ class LintGui: self.lbMessages.delete(0, END) for msg in self.msgs: if (self.msg_type_dict.get(msg[0])()): - msg_str = self.convert_to_string(msg) + msg_str = convert_to_string(msg) self.lbMessages.insert(END, msg_str) fg_color = COLORS.get(msg_str[:3], 'black') self.lbMessages.itemconfigure(END, fg=fg_color) @@ -323,13 +334,6 @@ class LintGui: except: pass - def convert_to_string(self, msg): - """make a string representation of a message""" - if (msg[2] != ""): - return "(" + msg[0] + ") " + msg[1] + "." + msg[2] + " [" + msg[3] + "]: " + msg[4] - else: - return "(" + msg[0] + ") " + msg[1] + " [" + msg[3] + "]: " + msg[4] - def process_incoming(self): """process the incoming messages from running pylint""" while self.msg_queue.qsize(): @@ -344,7 +348,7 @@ class LintGui: #displaying msg if message type is selected in check box if (self.msg_type_dict.get(msg[0])()): - msg_str = self.convert_to_string(msg) + msg_str = convert_to_string(msg) self.lbMessages.insert(END, msg_str) fg_color = COLORS.get(msg_str[:3], 'black') self.lbMessages.itemconfigure(END, fg=fg_color) @@ -451,7 +455,7 @@ class LintGui: def lint_thread(module, reporter, gui): """thread for pylint""" gui.status.text = "processing module(s)" - lint_obj = pylint.lint.Run(args=[module], reporter=reporter, exit=False) + pylint.lint.Run(args=[module], reporter=reporter, exit=False) gui.msg_queue.put("DONE") diff --git a/interfaces.py b/interfaces.py index 3d7bdad..e29026d 100644 --- a/interfaces.py +++ b/interfaces.py @@ -95,4 +95,4 @@ class IReporter(Interface): """ -__all__ = ('IRawChecker', 'IStatable', 'ILinter', 'IReporter') +__all__ = ('IRawChecker', 'ILinter', 'IReporter') @@ -47,20 +47,20 @@ from logilab.common.__pkginfo__ import version as common_version from logilab.astng import MANAGER, nodes, ASTNGBuildingException from logilab.astng.__pkginfo__ import version as astng_version -from pylint.utils import PyLintASTWalker, UnknownMessage, MessagesHandlerMixIn,\ - ReportsHandlerMixIn, MSG_TYPES, expand_modules +from pylint.utils import (PyLintASTWalker, UnknownMessage, MessagesHandlerMixIn, + ReportsHandlerMixIn, MSG_TYPES, expand_modules) from pylint.interfaces import ILinter, IRawChecker, IASTNGChecker -from pylint.checkers import BaseRawChecker, EmptyReport, \ - table_lines_from_stats -from pylint.reporters.text import TextReporter, ParseableTextReporter, \ - VSTextReporter, ColorizedTextReporter +from pylint.checkers import (BaseRawChecker, EmptyReport, + table_lines_from_stats) +from pylint.reporters.text import (TextReporter, ParseableTextReporter, + VSTextReporter, ColorizedTextReporter) from pylint.reporters.html import HTMLReporter from pylint import config from pylint.__pkginfo__ import version -OPTION_RGX = re.compile('\s*#*\s*pylint:(.*)') +OPTION_RGX = re.compile(r'\s*#*\s*pylint:(.*)') REPORTER_OPT_MAP = {'text': TextReporter, 'parseable': ParseableTextReporter, 'msvs': VSTextReporter, diff --git a/reporters/text.py b/reporters/text.py index 7b30c84..26dbd6d 100644 --- a/reporters/text.py +++ b/reporters/text.py @@ -90,6 +90,7 @@ class ParseableTextReporter(TextReporter): path = path.replace(self._prefix, '') self.writeln(self.line_format % locals()) + class VSTextReporter(ParseableTextReporter): """Visual studio text reporter""" line_format = '%(path)s(%(line)s): [%(sigle)s%(obj)s] %(msg)s' diff --git a/test/utils.py b/test/utils.py index 4060625..3cf1699 100644 --- a/test/utils.py +++ b/test/utils.py @@ -1,17 +1,14 @@ """some pylint test utilities """ -# # # # # pyreverse unittest utilities # # # # # # - -from logilab.common.testlib import TestCase import os import sys from os.path import join, dirname, abspath +from logilab.common.testlib import TestCase from logilab.astng import MANAGER - def _astng_wrapper(func, modname): return func(modname) diff --git a/testutils.py b/testutils.py index c61c2e4..bd9d4cb 100644 --- a/testutils.py +++ b/testutils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2003-2008 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2003-2012 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 @@ -15,22 +15,20 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """functional/non regression tests for pylint""" -import unittest import sys import re from glob import glob from os import linesep -from os.path import exists, abspath, dirname, join, basename, splitext +from os.path import abspath, dirname, join, basename, splitext from cStringIO import StringIO from logilab.common import testlib -from logilab.astng import MANAGER +from pylint import checkers from pylint.reporters import BaseReporter from pylint.interfaces import IReporter from pylint.lint import PyLinter -from pylint import checkers # Utils @@ -78,9 +76,9 @@ def get_tests_info(input_dir, msg_dir, prefix, suffix): result.append((infile, outfile)) return result + class TestReporter(BaseReporter): - """ store plain text messages - """ + """reporter storing plain text messages""" __implements____ = IReporter @@ -104,7 +102,7 @@ class TestReporter(BaseReporter): def finalize(self): self.messages.sort() for msg in self.messages: - print >>self.out, msg + print >> self.out, msg result = self.out.getvalue() self.reset() return result @@ -138,12 +136,13 @@ def exception_str(self, ex): # Test classes class LintTestUsingModule(testlib.TestCase): + INPUT_DIR = None DEFAULT_PACKAGE = 'input' package = DEFAULT_PACKAGE linter = linter module = None depends = None - + output = None _TEST_TYPE = 'module' def shortDescription(self): @@ -20,7 +20,6 @@ main pylint class import sys from warnings import warn -from os import linesep from os.path import dirname, basename, splitext, exists, isdir, join, normpath from logilab.common.modutils import modpath_from_file, get_module_files, \ @@ -176,14 +175,14 @@ class MessagesHandlerMixIn: # msgid is a category? catid = category_id(msgid) if catid is not None: - for msgid in self._msgs_by_category.get(catid): - self.disable(msgid, scope, line) + for _msgid in self._msgs_by_category.get(catid): + self.disable(_msgid, scope, line) return # msgid is a checker name? if msgid.lower() in self._checkers: for checker in self._checkers[msgid.lower()]: - for msgid in checker.msgs: - self.disable(msgid, scope, line) + for _msgid in checker.msgs: + self.disable(_msgid, scope, line) return # msgid is report id? if msgid.lower().startswith('rp'): |