summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Shaginaw <brian.shaginaw@warbyparker.com>2018-01-12 13:33:16 -0500
committerClaudiu Popa <pcmanticore@gmail.com>2018-01-19 17:37:53 +0100
commit6509bc9bcf459ae415e3cfeddce4e408bfdc2eb0 (patch)
treecc1121b0deb5f513d30d3b4d4efe238455b7f7b4
parent337c3647b4cacb8bc4efef1fcca595d4da3fcdb0 (diff)
downloadpylint-git-6509bc9bcf459ae415e3cfeddce4e408bfdc2eb0.tar.gz
Add test + fix for 'raise from function'.
-rw-r--r--pylint/checkers/utils.py2
-rw-r--r--pylint/test/unittest_checker_exceptions.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 1aff860e8..9d8a18ba5 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -467,6 +467,8 @@ def inherit_from_std_ex(node):
if node.name in ('Exception', 'BaseException') \
and node.root().name == EXCEPTIONS_MODULE:
return True
+ if not hasattr(node, 'ancestors'):
+ return False
return any(inherit_from_std_ex(parent)
for parent in node.ancestors(recurs=True))
diff --git a/pylint/test/unittest_checker_exceptions.py b/pylint/test/unittest_checker_exceptions.py
index a479c683b..39aa2ffda 100644
--- a/pylint/test/unittest_checker_exceptions.py
+++ b/pylint/test/unittest_checker_exceptions.py
@@ -60,3 +60,19 @@ class TestExceptionsChecker(CheckerTestCase):
message = Message('raising-bad-type', node=nodes[3], args='tuple')
with self.assertAddsMessages(message):
self.checker.visit_raise(nodes[3])
+
+ @pytest.mark.skipif(sys.version_info[0] != 3,
+ reason="The test is valid only on Python 3.")
+ def test_bad_exception_context_function(self):
+ node = astroid.extract_node("""
+ def function():
+ pass
+
+ try:
+ pass
+ except function as exc:
+ raise Exception from exc #@
+ """)
+ message = Message('bad-exception-context', node=node)
+ with self.assertAddsMessages(message):
+ self.checker.visit_raise(node)