Skip to content

Commit

Permalink
Fix a crash in the docparams extension when raising the result of…
Browse files Browse the repository at this point in the history
… a function (#6767)
  • Loading branch information
jacobtylerwalls committed May 31, 2022
1 parent fa416c3 commit bd33f79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Release date: TBA

Closes #6372

* Fixed a crash in the ``docparams`` extension involving raising the result of a function.

* Fixed failure to enable ``deprecated-module`` after a ``disable=all``
by making ``ImportsChecker`` solely responsible for emitting ``deprecated-module`` instead
of sharing responsibility with ``StdlibChecker``. (This could have led to double messages.)
Expand Down
2 changes: 2 additions & 0 deletions pylint/extensions/_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def possible_exc_types(node: nodes.NodeNG) -> set[nodes.ClassDef]:
exceptions = [target]
elif isinstance(target, nodes.FunctionDef):
for ret in target.nodes_of_class(nodes.Return):
if ret.value is None:
continue
if ret.frame(future=True) != target:
# return from inner function - ignore it
continue
Expand Down
11 changes: 11 additions & 0 deletions tests/extensions/test_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@ def test_exception(raise_node, expected):
for node in found_nodes:
assert isinstance(node, astroid.nodes.ClassDef)
assert {node.name for node in found_nodes} == expected


def test_possible_exc_types_raising_potential_none() -> None:
raise_node = astroid.extract_node(
"""
def a():
return
raise a() #@
"""
)
assert utils.possible_exc_types(raise_node) == set()

0 comments on commit bd33f79

Please sign in to comment.