From ab2454fed910d5b492f6b46eb31454d5809c07e6 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 14 Feb 2013 19:10:33 +0100 Subject: [PATCH] report unused variables also across closures --- Cython/Compiler/FlowControl.py | 3 +-- tests/errors/w_unused.pyx | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/FlowControl.py b/Cython/Compiler/FlowControl.py index 8ef14b1..4a218d7 100644 --- a/Cython/Compiler/FlowControl.py +++ b/Cython/Compiler/FlowControl.py @@ -616,8 +616,7 @@ def check_definitions(flow, compiler_directives): # Unused entries for entry in flow.entries: if (not entry.cf_references - and not entry.is_pyclass_attr - and not entry.in_closure): + and not entry.is_pyclass_attr): if entry.name != '_': # '_' is often used for unused variables, e.g. in loops if entry.is_arg: diff --git a/tests/errors/w_unused.pyx b/tests/errors/w_unused.pyx index b3c1581..980ecdf 100644 --- a/tests/errors/w_unused.pyx +++ b/tests/errors/w_unused.pyx @@ -38,6 +38,16 @@ def unused_and_unassigned(): def unused_generic(*args, **kwargs): pass +def unused_in_closure(a,b,c): + x = 1 + def inner(): + nonlocal c + c = 1 + y = 2 + return a+b + return inner() + + _ERRORS = """ 6:6: Unused entry 'a' 9:9: Unused entry 'b' @@ -49,4 +59,8 @@ _ERRORS = """ 36:13: Unused entry 'i' 38:20: Unused argument 'args' 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' """ -- 2.7.4