mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 14:54:17 +00:00
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:
parent
5758abe37d
commit
48749a67fe
2 changed files with 22 additions and 1 deletions
|
|
@ -341,7 +341,7 @@ class Checker(object):
|
||||||
self.addBinding(node.lineno, Assignment(name, node))
|
self.addBinding(node.lineno, Assignment(name, node))
|
||||||
|
|
||||||
def runException():
|
def runException():
|
||||||
for stmt in node.body:
|
for stmt in iter_child_nodes(node):
|
||||||
self.handleNode(stmt, node)
|
self.handleNode(stmt, node)
|
||||||
|
|
||||||
self.deferFunction(runException)
|
self.deferFunction(runException)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,21 @@ except (ImportError, ValueError):
|
||||||
print("err")
|
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):
|
class TestFlake(TestCase):
|
||||||
|
|
||||||
|
|
@ -35,3 +50,9 @@ class TestFlake(TestCase):
|
||||||
for c in (code, code2, code3):
|
for c in (code, code2, code3):
|
||||||
warnings = check(code)
|
warnings = check(code)
|
||||||
self.assertEqual(warnings, 0, 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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue