Skip to content

Commit

Permalink
Do not crash when calling unpack_infer. Close #998
Browse files Browse the repository at this point in the history
  • Loading branch information
PCManticore committed Jul 18, 2016
1 parent 56de570 commit bd95bdf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
===========================
Expand Down
13 changes: 8 additions & 5 deletions pylint/extensions/_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
35 changes: 35 additions & 0 deletions pylint/test/extensions/test_check_raise_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit bd95bdf

Please sign in to comment.