summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-06-01 16:28:53 +0800
committerClaudiu Popa <pcmanticore@gmail.com>2018-06-01 16:28:53 +0800
commit39cfb630a796fe90f8464b56bbd49949e7724588 (patch)
tree6fc1759702b3ca08feea7dc2ce494dd3a5fc359f
parent4a9e0913acf8bbc1d7796b5ea35ef6ceea867f54 (diff)
downloadpylint-git-39cfb630a796fe90f8464b56bbd49949e7724588.tar.gz
Check that the potential leaked names are not used in the except handler
-rw-r--r--pylint/checkers/python3.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index 76d2750e9..704f94b62 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -909,6 +909,13 @@ class Python3Checker(checkers.BaseChecker):
@utils.check_messages('unpacking-in-except', 'comprehension-escape')
def visit_excepthandler(self, node):
"""Visit an except handler block and check for exception unpacking."""
+ def _is_used_in_except_block(node):
+ scope = node.scope()
+ current = node
+ while current and current != scope and not isinstance(current, astroid.ExceptHandler):
+ current = current.parent
+ return isinstance(current, astroid.ExceptHandler) and current.type != node
+
if isinstance(node.name, (astroid.Tuple, astroid.List)):
self.add_message('unpacking-in-except', node=node)
return
@@ -927,6 +934,7 @@ class Python3Checker(checkers.BaseChecker):
scope_name
for scope_name in scope_names
if scope_name.name == node.name.name and scope_name.lineno > node.lineno
+ and not _is_used_in_except_block(scope_name)
]
reassignments_for_same_name = {
assign_name.lineno