From bd95bdf4fc265b15f35bafc19037cf54e2948628 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Mon, 18 Jul 2016 14:32:08 +0300 Subject: [PATCH] Do not crash when calling unpack_infer. Close #998 --- ChangeLog | 2 ++ pylint/extensions/_check_docs_utils.py | 13 ++++--- .../test/extensions/test_check_raise_docs.py | 35 +++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58a080bb8c..1b64abb15d 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 39d7550b71..f1884d7581 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 e39a155a24..633d19b26a 100644 --- a/pylint/test/extensions/test_check_raise_docs.py +++ b/pylint/test/extensions/test_check_raise_docs.py @@ -352,5 +352,40 @@ def my_func(self): 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()