diff options
Diffstat (limited to 'pyflakes/test/test_undefined_names.py')
-rw-r--r-- | pyflakes/test/test_undefined_names.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/pyflakes/test/test_undefined_names.py b/pyflakes/test/test_undefined_names.py index 1464d8e..3d19210 100644 --- a/pyflakes/test/test_undefined_names.py +++ b/pyflakes/test/test_undefined_names.py @@ -25,15 +25,16 @@ class Test(TestCase): @skipIf(version_info < (3,), 'in Python 2 exception names stay bound after the except: block') def test_undefinedExceptionName(self): - """Exception names can't be used after the except: block.""" + """Exception names can't be used after the except: block. + + The exc variable is unused inside the exception handler.""" self.flakes(''' try: raise ValueError('ve') except ValueError as exc: pass exc - ''', - m.UndefinedName) + ''', m.UndefinedName, m.UnusedVariable) def test_namesDeclaredInExceptBlocks(self): """Locals declared in except: blocks can be used after the block. @@ -71,7 +72,8 @@ class Test(TestCase): """Exception names are unbound after the `except:` block. Last line will raise UnboundLocalError on Python 3 but would print out - 've' on Python 2.""" + 've' on Python 2. The exc variable is unused inside the exception + handler.""" self.flakes(''' try: raise ValueError('ve') @@ -79,14 +81,15 @@ class Test(TestCase): pass print(exc) exc = 'Original value' - ''', - m.UndefinedName) + ''', m.UndefinedName, m.UnusedVariable) def test_undefinedExceptionNameObscuringLocalVariableFalsePositive1(self): """Exception names obscure locals, can't be used after. Unless. Last line will never raise UnboundLocalError because it's only entered if no exception was raised.""" + # The exc variable is unused inside the exception handler. + expected = [] if version_info < (3,) else [m.UnusedVariable] self.flakes(''' exc = 'Original value' try: @@ -95,7 +98,7 @@ class Test(TestCase): print('exception logged') raise exc - ''') + ''', *expected) def test_delExceptionInExcept(self): """The exception name can be deleted in the except: block.""" @@ -111,6 +114,8 @@ class Test(TestCase): Last line will never raise UnboundLocalError because `error` is only falsy if the `except:` block has not been entered.""" + # The exc variable is unused inside the exception handler. + expected = [] if version_info < (3,) else [m.UnusedVariable] self.flakes(''' exc = 'Original value' error = None @@ -122,7 +127,7 @@ class Test(TestCase): print(error) else: exc - ''') + ''', *expected) @skip('error reporting disabled due to false positives below') def test_undefinedExceptionNameObscuringGlobalVariable(self): @@ -168,6 +173,8 @@ class Test(TestCase): Last line will never raise NameError because it's only entered if no exception was raised.""" + # The exc variable is unused inside the exception handler. + expected = [] if version_info < (3,) else [m.UnusedVariable] self.flakes(''' exc = 'Original value' def func(): @@ -178,13 +185,15 @@ class Test(TestCase): print('exception logged') raise exc - ''') + ''', *expected) def test_undefinedExceptionNameObscuringGlobalVariableFalsePositive2(self): """Exception names obscure globals, can't be used after. Unless. Last line will never raise NameError because `error` is only falsy if the `except:` block has not been entered.""" + # The exc variable is unused inside the exception handler. + expected = [] if version_info < (3,) else [m.UnusedVariable] self.flakes(''' exc = 'Original value' def func(): @@ -198,7 +207,7 @@ class Test(TestCase): print(error) else: exc - ''') + ''', *expected) def test_functionsNeedGlobalScope(self): self.flakes(''' |