Commit ab2454fe authored by Stefan Behnel's avatar Stefan Behnel

report unused variables also across closures

parent 0b657721
...@@ -616,8 +616,7 @@ def check_definitions(flow, compiler_directives): ...@@ -616,8 +616,7 @@ def check_definitions(flow, compiler_directives):
# Unused entries # Unused entries
for entry in flow.entries: for entry in flow.entries:
if (not entry.cf_references if (not entry.cf_references
and not entry.is_pyclass_attr and not entry.is_pyclass_attr):
and not entry.in_closure):
if entry.name != '_': if entry.name != '_':
# '_' is often used for unused variables, e.g. in loops # '_' is often used for unused variables, e.g. in loops
if entry.is_arg: if entry.is_arg:
......
...@@ -38,6 +38,16 @@ def unused_and_unassigned(): ...@@ -38,6 +38,16 @@ def unused_and_unassigned():
def unused_generic(*args, **kwargs): def unused_generic(*args, **kwargs):
pass pass
def unused_in_closure(a,b,c):
x = 1
def inner():
nonlocal c
c = 1
y = 2
return a+b
return inner()
_ERRORS = """ _ERRORS = """
6:6: Unused entry 'a' 6:6: Unused entry 'a'
9:9: Unused entry 'b' 9:9: Unused entry 'b'
...@@ -49,4 +59,8 @@ _ERRORS = """ ...@@ -49,4 +59,8 @@ _ERRORS = """
36:13: Unused entry 'i' 36:13: Unused entry 'i'
38:20: Unused argument 'args' 38:20: Unused argument 'args'
38:28: Unused argument 'kwargs' 38:28: Unused argument 'kwargs'
41:26: Unused argument 'c'
41:26: Unused entry 'c'
42:6: Unused entry 'x'
46:10: Unused entry 'y'
""" """
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment