From 1003eeabe881882ee1da163fa53a85a28296329b Mon Sep 17 00:00:00 2001 From: Tarek Ziade Date: Tue, 21 Feb 2012 10:43:16 +0100 Subject: [PATCH] make sure the name of the exception is added in the scope of the exception - fixes #10 --- flake8/pyflakes.py | 7 +++++-- flake8/tests/test_flakes.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 flake8/tests/test_flakes.py diff --git a/flake8/pyflakes.py b/flake8/pyflakes.py index ec1b1d6..c83d210 100644 --- a/flake8/pyflakes.py +++ b/flake8/pyflakes.py @@ -329,7 +329,10 @@ class Checker(object): EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore # additional node types - COMPREHENSION = EXCEPTHANDLER = KEYWORD = handleChildren + COMPREHENSION = KEYWORD = handleChildren + + def EXCEPTHANDLER(self, node): + self.scope[node.name] = node def addBinding(self, lineno, value, reportRedef=True): '''Called when a binding is altered. @@ -645,7 +648,7 @@ def checkPath(filename): return 1 -def check(codeString, filename): +def check(codeString, filename='(code)'): """ Check the Python source given by C{codeString} for flakes. diff --git a/flake8/tests/test_flakes.py b/flake8/tests/test_flakes.py new file mode 100644 index 0000000..815e61e --- /dev/null +++ b/flake8/tests/test_flakes.py @@ -0,0 +1,17 @@ +from unittest import TestCase +from flake8.pyflakes import check + + +code = """ +try: + pass +except ValueError as err: + print(err) +""" + + +class TestFlake(TestCase): + + def test_exception(self): + warnings = check(code) + self.assertEqual(warnings, 0)