From 49685b3fb20b8a7562260458562d36d669177223 Mon Sep 17 00:00:00 2001
From: Daira Hopwood <daira@jacaranda.org>
Date: Thu, 5 Sep 2013 19:11:16 +0100
Subject: [PATCH] Sun Oct  9 05:47:10 BST 2011  david-sarah@jacaranda.org   *
 check-miscaptures.py: handle destructuring function arguments correctly. refs
 #1555

---
 misc/coding_tools/check-miscaptures.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/misc/coding_tools/check-miscaptures.py b/misc/coding_tools/check-miscaptures.py
index 81422adb..9820a8a3 100644
--- a/misc/coding_tools/check-miscaptures.py
+++ b/misc/coding_tools/check-miscaptures.py
@@ -88,10 +88,8 @@ def collect_captured(ast, assigned, captured, in_function_yet):
         if isinstance(ast, (Lambda, Function)):
             # Formal parameters of the function are excluded from
             # captures we care about in subnodes of the function body.
-            assigned = assigned.copy()
-            for argname in ast.argnames:
-                if argname in assigned:
-                    del assigned[argname]
+            new_assigned = assigned.copy()
+            remove_argnames(ast.argnames, new_assigned)
 
             if len(new_assigned) > 0:
                 for child in childnodes[len(ast.defaults):]:
@@ -109,6 +107,14 @@ def collect_captured(ast, assigned, captured, in_function_yet):
                 collect_captured(child, assigned, captured, True)
 
 
+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,)
-- 
2.45.2