summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-07-18 14:32:08 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2016-07-18 14:42:41 +0300
commitbd95bdf4fc265b15f35bafc19037cf54e2948628 (patch)
tree34aefb68c4a0ff439874b3df63c36f6203b191ff
parent56de57047b14e312cf55403b62a8284cf02427e2 (diff)
downloadpylint-git-bd95bdf4fc265b15f35bafc19037cf54e2948628.tar.gz
Do not crash when calling unpack_infer. Close #998
-rw-r--r--ChangeLog2
-rw-r--r--pylint/extensions/_check_docs_utils.py13
-rw-r--r--pylint/test/extensions/test_check_raise_docs.py35
3 files changed, 45 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 58a080bb8..1b64abb15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,7 +7,9 @@ What's new in Pylint 1.6.3?
Release date: tba
+ * Do not crash when inferring uninferable exception types for docparams extension
+ Close #998
What's new in Pylint 1.6.2?
===========================
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py
index 39d7550b7..f1884d758 100644
--- a/pylint/extensions/_check_docs_utils.py
+++ b/pylint/extensions/_check_docs_utils.py
@@ -68,11 +68,14 @@ def possible_exc_types(node):
handler = handler.parent
if handler and handler.type:
- excs = astroid.unpack_infer(handler.type)
- excs = (exc.name for exc in excs if exc is not astroid.YES)
-
- excs = set(exc for exc in excs if not node_ignores_exception(node, exc))
- return excs
+ inferred_excs = astroid.unpack_infer(handler.type)
+ excs = (exc.name for exc in inferred_excs
+ if exc is not astroid.YES)
+
+ try:
+ return set(exc for exc in excs if not node_ignores_exception(node, exc))
+ except astroid.InferenceError:
+ return ()
def docstringify(docstring):
for docstring_type in [SphinxDocstring, GoogleDocstring, NumpyDocstring]:
diff --git a/pylint/test/extensions/test_check_raise_docs.py b/pylint/test/extensions/test_check_raise_docs.py
index e39a155a2..633d19b26 100644
--- a/pylint/test/extensions/test_check_raise_docs.py
+++ b/pylint/test/extensions/test_check_raise_docs.py
@@ -352,5 +352,40 @@ class DocstringCheckerRaiseTest(CheckerTestCase):
with self.assertNoMessages():
self.checker.visit_raise(raise_node)
+ def test_no_crash_when_inferring_handlers(self):
+ raise_node = test_utils.extract_node('''
+ import collections
+
+ def test():
+ """raises
+
+ :raise U: pass
+ """
+ try:
+ pass
+ except collections.U as exc:
+ raise #@
+ ''')
+ with self.assertNoMessages():
+ self.checker.visit_raise(raise_node)
+
+ def test_no_crash_when_cant_find_exception(self):
+ raise_node = test_utils.extract_node('''
+ import collections
+
+ def test():
+ """raises
+
+ :raise U: pass
+ """
+ try:
+ pass
+ except U as exc:
+ raise #@
+ ''')
+ with self.assertNoMessages():
+ self.checker.visit_raise(raise_node)
+
+
if __name__ == '__main__':
unittest.main()