Fixed the W402 (imported but unused) bug in flake8's fork of pyflakes.

Added a couple of tests that fail without this patch.
This commit is contained in:
Gustavo Picon 2012-03-21 01:02:35 -05:00
parent 5758abe37d
commit 48749a67fe
2 changed files with 22 additions and 1 deletions

View file

@ -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)

View file

@ -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)