From e648e23980d361c8504d41d6b94f9659199ce060 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sat, 21 Nov 2015 19:42:08 +0200 Subject: Cleanup pylint issues This changeset also brings a couple of changes: * rrheaders and rcheaders are dropped from html_writer.Table's constructor. They weren't used at all and it was dead code. This simplified some if statements. * _is_attribute_property is used to look for a property assignment instead on relying on a different implementation. --- pylint/checkers/base.py | 2 +- pylint/checkers/classes.py | 15 ++++++--------- pylint/checkers/design_analysis.py | 18 +++++++++--------- pylint/checkers/newstyle.py | 1 - pylint/checkers/typecheck.py | 3 +-- pylint/checkers/variables.py | 2 +- pylint/graph.py | 5 +---- pylint/pyreverse/diadefslib.py | 5 +---- pylint/reporters/ureports/html_writer.py | 6 +----- pylint/reporters/ureports/nodes.py | 4 +--- 10 files changed, 22 insertions(+), 39 deletions(-) diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 001a70c..cc7c786 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -1678,7 +1678,7 @@ class ElifChecker(BaseTokenChecker): @staticmethod def _is_bool_const(node): return (isinstance(node.value, astroid.Const) - and isinstance(node.value.value, bool)) + and isinstance(node.value.value, bool)) def _is_actual_elif(self, node): """Check if the given node is an actual elif diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 2dc45e1..6763f74 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -723,16 +723,13 @@ a metaclass class method.'} # b = property(lambda: self._b) stmt = node.parent.statement() - try: - if (isinstance(stmt, astroid.Assign) and - (stmt in klass.body or klass.parent_of(stmt)) and - isinstance(stmt.value, astroid.Call) and - isinstance(stmt.value.func, astroid.Name) and - stmt.value.func.name == 'property' and - is_builtin_object(next(stmt.value.func.infer(), None))): + if (isinstance(stmt, astroid.Assign) + and len(stmt.targets) == 1 + and isinstance(stmt.targets[0], astroid.AssignName)): + name = stmt.targets[0].name + if _is_attribute_property(name, klass): return - except astroid.InferenceError: - pass + self.add_message('protected-access', node=node, args=attrname) def visit_name(self, node): diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index fc10e3f..500b158 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -154,13 +154,13 @@ class MisdesignChecker(BaseChecker): 'help' : 'Maximum number of public methods for a class \ (see R0904).'} ), - ('max-bool-expr', - {'default': 5, - 'type': 'int', - 'metavar': '', - 'help': 'Maximum number of boolean expressions in a if ' - 'statement'} - ), + ('max-bool-expr', + {'default': 5, + 'type': 'int', + 'metavar': '', + 'help': 'Maximum number of boolean expressions in a if ' + 'statement'} + ), ) def __init__(self, linter=None): @@ -322,8 +322,8 @@ class MisdesignChecker(BaseChecker): return nb_bool_expr = _count_boolean_expressions(condition) if nb_bool_expr > self.config.max_bool_expr: - self.add_message('too-many-boolean-expressions', node=condition, - args=(nb_bool_expr, self.config.max_bool_expr)) + self.add_message('too-many-boolean-expressions', node=condition, + args=(nb_bool_expr, self.config.max_bool_expr)) def visit_while(self, node): """increments the branches counter""" diff --git a/pylint/checkers/newstyle.py b/pylint/checkers/newstyle.py index 30bc6a6..489c22f 100644 --- a/pylint/checkers/newstyle.py +++ b/pylint/checkers/newstyle.py @@ -24,7 +24,6 @@ from pylint.checkers import BaseChecker from pylint.checkers.utils import ( check_messages, node_frame_class, - safe_infer, has_known_bases ) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index da9daf7..e5f60d6 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -27,7 +27,6 @@ import astroid.context import astroid.arguments from astroid import exceptions from astroid import objects -from astroid import node_classes from astroid import bases import six @@ -56,7 +55,7 @@ def _unflatten(iterable): if (isinstance(elem, collections.Sequence) and not isinstance(elem, six.string_types)): for elem in _unflatten(elem): - yield elem + yield elem elif elem and not index: # We're interested only in the first element. yield elem diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index af87776..f0f0fa0 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -32,7 +32,7 @@ from pylint.checkers.utils import ( assign_parent, check_messages, is_inside_except, clobber_in_except, get_all_elements, has_known_bases, node_ignores_exception, is_inside_abstract_class, is_comprehension, is_iterable, - safe_infer, has_known_bases) + safe_infer) import six SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$") diff --git a/pylint/graph.py b/pylint/graph.py index 492f8fd..76d254c 100644 --- a/pylint/graph.py +++ b/pylint/graph.py @@ -101,10 +101,7 @@ class DotBackend(object): pdot.write(self.source) pdot.close() if target != 'dot': - if sys.platform == 'win32': - use_shell = True - else: - use_shell = False + use_shell = sys.platform == 'win32' if mapfile: subprocess.call([self.renderer, '-Tcmapx', '-o', mapfile, '-T', target, dot_sourcepath, diff --git a/pylint/pyreverse/diadefslib.py b/pylint/pyreverse/diadefslib.py index 6c2cb3c..0d3a963 100644 --- a/pylint/pyreverse/diadefslib.py +++ b/pylint/pyreverse/diadefslib.py @@ -49,10 +49,7 @@ class DiaDefGenerator(object): # if we have a class diagram, we want more information by default; # so if the option is None, we return True if option is None: - if self.config.classes: - return True - else: - return False + return bool(self.config.classes) return option def _set_default_options(self): diff --git a/pylint/reporters/ureports/html_writer.py b/pylint/reporters/ureports/html_writer.py index c5f74d3..b3db270 100644 --- a/pylint/reporters/ureports/html_writer.py +++ b/pylint/reporters/ureports/html_writer.py @@ -61,16 +61,12 @@ class HTMLWriter(BaseWriter): for i, row in enumerate(table_content): if i == 0 and layout.rheaders: self.writeln(u'') - elif i+1 == len(table_content) and layout.rrheaders: - self.writeln(u'') else: self.writeln(u'' % (u'even' if i % 2 else u'odd')) for j, cell in enumerate(row): cell = cell or u' ' if (layout.rheaders and i == 0) or \ - (layout.cheaders and j == 0) or \ - (layout.rrheaders and i+1 == len(table_content)) or \ - (layout.rcheaders and j+1 == len(row)): + (layout.cheaders and j == 0): self.writeln(u'%s' % cell) else: self.writeln(u'%s' % cell) diff --git a/pylint/reporters/ureports/nodes.py b/pylint/reporters/ureports/nodes.py index 104ba83..9bd9c10 100644 --- a/pylint/reporters/ureports/nodes.py +++ b/pylint/reporters/ureports/nodes.py @@ -171,7 +171,7 @@ class Table(BaseLayout): * title : the table's optional title """ def __init__(self, cols, title=None, - rheaders=0, cheaders=0, rrheaders=0, rcheaders=0, + rheaders=0, cheaders=0, **kwargs): super(Table, self).__init__(**kwargs) assert isinstance(cols, int) @@ -179,5 +179,3 @@ class Table(BaseLayout): self.title = title self.rheaders = rheaders self.cheaders = cheaders - self.rrheaders = rrheaders - self.rcheaders = rcheaders -- cgit v1.2.1