diff options
author | Sylvain Thenault <sylvain.thenault@logilab.fr> | 2008-12-03 09:39:42 +0100 |
---|---|---|
committer | Sylvain Thenault <sylvain.thenault@logilab.fr> | 2008-12-03 09:39:42 +0100 |
commit | ec17197ca63ebd93405ad679c8ecfc594f218942 (patch) | |
tree | 622d524634745cfaba6a321be5ec7e73b6cb0298 /checkers/variables.py | |
parent | c931eab5334a3c6988b8239018a886c9bd2d97cc (diff) | |
download | pylint-ec17197ca63ebd93405ad679c8ecfc594f218942.tar.gz |
* include a modified version of Maarten ter Huurne patch of avoid W0613
warning on arguments from overridden method
Diffstat (limited to 'checkers/variables.py')
-rw-r--r-- | checkers/variables.py | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/checkers/variables.py b/checkers/variables.py index 71fb0eb..7f8ab2b 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -1,4 +1,4 @@ -# Copyright (c) 2003-2007 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2003-2008 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 @@ -29,6 +29,23 @@ from pylint.checkers.utils import is_error, is_builtin, is_func_default, \ is_defined_before #, is_parent, FOR_NODE_TYPES +def overridden_method(klass, name): + """get overriden method if any""" + try: + parent = klass.local_attr_ancestors(name).next() + except (StopIteration, KeyError): + return None + try: + meth_node = parent[name] + except KeyError: + # We have found an ancestor defining <name> but it's not in the local + # dictionary. This may happen with astng built from living objects. + return None + # check its a method + if getattr(meth_node, 'argnames', None) is not None: + return meth_node + return None + MSGS = { 'E0601': ('Using variable %r before assignment', @@ -192,19 +209,20 @@ builtins. Remember that you should avoid to define new builtins when possible.' self._vars.append({}) def leave_function(self, node): - """leave function: check function's locals are consumed - """ + """leave function: check function's locals are consumed""" not_consumed = self._to_consume.pop()[0] self._vars.pop(0) + # don't check arguments of function which are only raising an exception + if is_error(node): + return + # don't check arguments of abstract methods or within an interface is_method = node.is_method() klass = node.parent.frame() - # don't check arguments of abstract methods or within an interface if is_method and (klass.type == 'interface' or node.is_abstract()): return - if is_error(node): - return authorized_rgx = self.config.dummy_variables_rgx - for name, stmts in not_consumed.items(): + overridden = marker = [] + for name, stmts in not_consumed.iteritems(): # ignore some special names specified by user configuration if authorized_rgx.match(name): continue @@ -215,9 +233,16 @@ builtins. Remember that you should avoid to define new builtins when possible.' continue # care about functions with unknown argument (builtins) if node.argnames is not None and name in node.argnames: - # don't warn if the first argument of a method is not used - if is_method and node.argnames and name == node.argnames[0]: - continue + if is_method: + # don't warn for the first argument of a (non static) method + if node.type != 'staticmethod' and \ + node.argnames and name == node.argnames[0]: + continue + # don't warn for argument of an overridden method + if overridden is marker: + overridden = overridden_method(klass, node.name) + if overridden is not None and name in overridden.argnames: + continue # don't check callback arguments if node.name.startswith('cb_') or \ node.name.endswith('_cb'): |