diff options
author | Emile Anclin <emile.anclin@logilab.fr> | 2009-03-10 17:20:28 +0100 |
---|---|---|
committer | Emile Anclin <emile.anclin@logilab.fr> | 2009-03-10 17:20:28 +0100 |
commit | 7200bd9d9a59d7944ae489a8ba735f35607e2714 (patch) | |
tree | 19e1f9431b2f7549818f1f89d5bc69b80672f310 /checkers/utils.py | |
parent | c18e39f1dc52cb9cfc476b1f9a5fd2aa668e097c (diff) | |
download | pylint-7200bd9d9a59d7944ae489a8ba735f35607e2714.tar.gz |
fix default value Name nodes
Diffstat (limited to 'checkers/utils.py')
-rw-r--r-- | checkers/utils.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/checkers/utils.py b/checkers/utils.py index d15ece0..209b018 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -122,16 +122,32 @@ def is_defined_before(var_node, comp_node_types=COMP_NODE_TYPES): _node = _node.previous_sibling() return False -def is_func_default(node): +def is_func_default(node, name): """return true if the name is used in function default argument's value """ parent = node.parent if parent is None: return 0 - if isinstance(parent, astng.Function) and parent.args.defaults and \ - node in parent.args.defaults: - return 1 - return is_func_default(parent) + 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(node, names=None): + """return a list of all names in arg.defaults, including func calls""" + if names is None: + names = [] + if isinstance(node, (list, tuple)): + for elt in node: + _child_names(elt, names) + else: + for child in node.get_children(): + if isinstance(child, astng.Name): + names.append(child.name) + else: + _child_names(child, names) + return names def is_func_decorator(node): """return true if the name is used in function decorator |