From 48749a67fe0a8eae1493633682dcabdab6ab2953 Mon Sep 17 00:00:00 2001 From: Gustavo Picon Date: Wed, 21 Mar 2012 01:02:35 -0500 Subject: [PATCH] Fixed the W402 (imported but unused) bug in flake8's fork of pyflakes. Added a couple of tests that fail without this patch. --- flake8/pyflakes.py | 2 +- flake8/tests/test_flakes.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/flake8/pyflakes.py b/flake8/pyflakes.py index e80968d..98100ae 100644 --- a/flake8/pyflakes.py +++ b/flake8/pyflakes.py @@ -341,7 +341,7 @@ class Checker(object): self.addBinding(node.lineno, Assignment(name, node)) def runException(): - for stmt in node.body: + for stmt in iter_child_nodes(node): self.handleNode(stmt, node) self.deferFunction(runException) diff --git a/flake8/tests/test_flakes.py b/flake8/tests/test_flakes.py index da10034..9ab3c12 100644 --- a/flake8/tests/test_flakes.py +++ b/flake8/tests/test_flakes.py @@ -28,6 +28,21 @@ except (ImportError, ValueError): print("err") """ +code_from_import_exception = """ +from foo import SomeException +try: + pass +except SomeException: + print("err") +""" + +code_import_exception = """ +import foo.SomeException +try: + pass +except foo.SomeException: + print("err") +""" class TestFlake(TestCase): @@ -35,3 +50,9 @@ class TestFlake(TestCase): for c in (code, code2, code3): warnings = check(code) self.assertEqual(warnings, 0, code) + + def test_from_import_exception_in_scope(self): + self.assertEqual(check(code_from_import_exception), 0) + + def test_import_exception_in_scope(self): + self.assertEqual(check(code_import_exception), 0)