Skip to content

Commit

Permalink
fix: Prevent infinite recursion while expanding exports
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Sep 22, 2022
1 parent 7e816ed commit 68446f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,25 @@ def resolve_aliases( # noqa: WPS231
)
return unresolved, iteration

def expand_exports(self, module: Module) -> None:
def expand_exports(self, module: Module, seen: set | None = None) -> None:
"""Expand exports: try to recursively expand all module exports.
Parameters:
module: The module to recurse on.
seen: Used to avoid infinite recursion.
"""
seen = seen or set()
seen.add(module.path)
if module.exports is None:
return
expanded = set()
for export in module.exports:
if isinstance(export, Name):
module_path = export.full.rsplit(".", 1)[0] # remove trailing .__all__
next_module = self.modules_collection[module_path]
self.expand_exports(next_module)
expanded |= next_module.exports
if next_module.path not in seen:
self.expand_exports(next_module, seen)
expanded |= next_module.exports
else:
expanded.add(export)
module.exports = expanded
Expand Down

0 comments on commit 68446f7

Please sign in to comment.