Skip to content

Commit

Permalink
fix: Don't crash on nested functions in __init__ methods
Browse files Browse the repository at this point in the history
Issue #68: #68
  • Loading branch information
pawamoy committed May 7, 2022
1 parent 5cdf185 commit cd5af43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/griffe/agents/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def handle_function(self, node: ast.AsyncFunctionDef | ast.FunctionDef, labels:
base_property.labels.add("deletable")
else:
self.current[node.name] = function
if self.current.overloads[function.name]:
if self.current.kind in {Kind.MODULE, Kind.CLASS} and self.current.overloads[function.name]:
function.overloads = self.current.overloads[function.name]
del self.current.overloads[function.name] # noqa: WPS420

Expand Down
14 changes: 14 additions & 0 deletions tests/test_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,17 @@ def test_parse_complex__all__assignments(statements):
loader.resolve_aliases()

assert package.exports == {"CONST_INIT", "CONST_A", "CONST_B", "CONST_C"}


# issue https://github.com/mkdocstrings/griffe/issues/68
def test_dont_crash_on_nested_functions_in_init():
"""Assert we don't crash when visiting a nested function in `__init__` methods."""
with temporary_visited_module(
"""
class C:
def __init__(self):
def pl(i: int):
return i + 1
"""
) as module:
assert module

0 comments on commit cd5af43

Please sign in to comment.