mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-23 09:15:32 +00:00
check-miscaptures.py: handle destructuring function arguments correctly. refs #1555
This commit is contained in:
@ -96,10 +96,8 @@ def collect_captured(ast, declared, captured):
|
|||||||
if isinstance(ast, (Lambda, Function)):
|
if isinstance(ast, (Lambda, Function)):
|
||||||
# Formal parameters of the function are excluded from
|
# Formal parameters of the function are excluded from
|
||||||
# captures we care about in subnodes of the function body.
|
# captures we care about in subnodes of the function body.
|
||||||
declared = declared.copy()
|
new_declared = declared.copy()
|
||||||
for argname in ast.argnames:
|
remove_argnames(ast.argnames, new_declared)
|
||||||
if argname in declared:
|
|
||||||
del declared[argname]
|
|
||||||
|
|
||||||
for child in childnodes[len(ast.defaults):]:
|
for child in childnodes[len(ast.defaults):]:
|
||||||
collect_captured(child, declared, captured)
|
collect_captured(child, declared, captured)
|
||||||
@ -114,6 +112,14 @@ def collect_captured(ast, declared, captured):
|
|||||||
collect_captured(child, 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):
|
def make_result(funcnode, var_name, var_lineno):
|
||||||
if hasattr(funcnode, 'name'):
|
if hasattr(funcnode, 'name'):
|
||||||
func_name = 'function %r' % (funcnode.name,)
|
func_name = 'function %r' % (funcnode.name,)
|
||||||
|
Reference in New Issue
Block a user