From: david-sarah Date: Sun, 9 Oct 2011 04:47:10 +0000 (+0000) Subject: check-miscaptures.py: handle destructuring function arguments correctly. refs #1555 X-Git-Url: https://git.rkrishnan.org/pf/content/en/using.html?a=commitdiff_plain;h=1c6fe1d23080396d0e38a5202302b79c450343ba;p=tahoe-lafs%2Ftahoe-lafs.git check-miscaptures.py: handle destructuring function arguments correctly. refs #1555 --- diff --git a/misc/coding_tools/check-miscaptures.py b/misc/coding_tools/check-miscaptures.py index 2e827fb9..c1ced6c3 100644 --- a/misc/coding_tools/check-miscaptures.py +++ b/misc/coding_tools/check-miscaptures.py @@ -96,10 +96,8 @@ def collect_captured(ast, declared, captured): if isinstance(ast, (Lambda, Function)): # Formal parameters of the function are excluded from # captures we care about in subnodes of the function body. - declared = declared.copy() - for argname in ast.argnames: - if argname in declared: - del declared[argname] + new_declared = declared.copy() + remove_argnames(ast.argnames, new_declared) for child in childnodes[len(ast.defaults):]: collect_captured(child, declared, captured) @@ -114,6 +112,14 @@ def collect_captured(ast, declared, captured): collect_captured(child, declared, captured) +def remove_argnames(names, fromset): + for element in names: + if element in fromset: + del fromset[element] + elif isinstance(element, (tuple, list)): + remove_argnames(element, fromset) + + def make_result(funcnode, var_name, var_lineno): if hasattr(funcnode, 'name'): func_name = 'function %r' % (funcnode.name,)