mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 06:14:17 +00:00
make sure the name of the exception is added in the scope of the exception - fixes #10
This commit is contained in:
parent
b1690f818d
commit
1003eeabe8
2 changed files with 22 additions and 2 deletions
|
|
@ -329,7 +329,10 @@ class Checker(object):
|
||||||
EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore
|
EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore
|
||||||
|
|
||||||
# additional node types
|
# 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):
|
def addBinding(self, lineno, value, reportRedef=True):
|
||||||
'''Called when a binding is altered.
|
'''Called when a binding is altered.
|
||||||
|
|
@ -645,7 +648,7 @@ def checkPath(filename):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def check(codeString, filename):
|
def check(codeString, filename='(code)'):
|
||||||
"""
|
"""
|
||||||
Check the Python source given by C{codeString} for flakes.
|
Check the Python source given by C{codeString} for flakes.
|
||||||
|
|
||||||
|
|
|
||||||
17
flake8/tests/test_flakes.py
Normal file
17
flake8/tests/test_flakes.py
Normal file
|
|
@ -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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue