diff options
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | checkers/utils.py | 25 | ||||
| -rw-r--r-- | checkers/variables.py | 4 | ||||
| -rw-r--r-- | elisp/pylint.el | 2 | ||||
| -rw-r--r-- | test/input/func_w0613.py | 11 |
5 files changed, 24 insertions, 22 deletions
@@ -1,7 +1,9 @@ ChangeLog for PyLint ==================== - +-- + * fix #8687, W0613 false positive on inner function + 2009-03-19 -- 0.17.0 * semicolon check : move W0601 to W0301 * remove rpython : remove all rpython checker, modules and tests diff --git a/checkers/utils.py b/checkers/utils.py index 41b09e38d..321ecb800 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -122,26 +122,17 @@ def is_defined_before(var_node, comp_node_types=COMP_NODE_TYPES): _node = _node.previous_sibling() return False -def is_func_default(node, name=None): - """return true if the name is used in function default argument's value +def is_func_default(node): + """return true if the given Name node is used in function default argument's + value """ - if name == None: - name = node.name parent = node.parent - if parent is None: - return 0 if isinstance(parent, astng.Function): - defaults = parent.args.defaults - if name in _child_names(defaults): - return 1 - return is_func_default(parent, name) - -def _child_names(nodes): - """return a list of all Name in a list 'nodes' """ - names = [] - for node in nodes: - names.extend(n.name for n in node.nodes_of_class(astng.Name)) - return names + for default_node in parent.args.defaults: + for default_name_node in default_node.nodes_of_class(astng.Name): + if default_name_node is node: + return True + return False def is_func_decorator(node): """return true if the name is used in function decorator diff --git a/checkers/variables.py b/checkers/variables.py index 201fab64a..9d010275a 100644 --- a/checkers/variables.py +++ b/checkers/variables.py @@ -326,8 +326,8 @@ builtins. Remember that you should avoid to define new builtins when possible.' # if the name node is used as a function default argument's value or as # a decorator, then start from the parent frame of the function instead # of the function frame - and thus open an inner class scope - if (is_func_default(node, node.name) or is_func_decorator(node) - or is_ancestor_name(frame, node)): + if (is_func_default(node) or is_func_decorator(node) + or is_ancestor_name(frame, node)): start_index = len(self._to_consume) - 2 else: start_index = len(self._to_consume) - 1 diff --git a/elisp/pylint.el b/elisp/pylint.el index 5862a2e3a..a9b22b174 100644 --- a/elisp/pylint.el +++ b/elisp/pylint.el @@ -1,5 +1,3 @@ -(require 'compile) - ;; ;; Modifications done by Yarosav O. Halchenko (2008): ;; - enable user-visible variables diff --git a/test/input/func_w0613.py b/test/input/func_w0613.py index a25211f10..3bf57674d 100644 --- a/test/input/func_w0613.py +++ b/test/input/func_w0613.py @@ -22,3 +22,14 @@ class AAAA: """called by the registry when the vobject has been selected. """ return cls + + def using_inner_function(self, etype, size=1): + """return a fake result set for a particular entity type""" + rset = AAAA([('A',)]*size, '%s X' % etype, + description=[(etype,)]*size) + def inner(row, col=0, etype=etype, req=self, rset=rset): + """inner using all its argument""" + # pylint: disable-msg = E1103 + return req.vreg.etype_class(etype)(req, rset, row, col) + # pylint: disable-msg = W0201 + rset.get_entity = inner |
