Skip to content

Commit

Permalink
fix: Fix detecting whether an object should be an alias during inspec…
Browse files Browse the repository at this point in the history
…tion

Issue #180: #180
  • Loading branch information
pawamoy committed Jul 17, 2023
1 parent d34a3ba commit 6a63b37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/griffe/agents/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ def get_module(self, import_paths: Sequence[str | Path] | None = None) -> Module
if self.parent is not None:
import_path = f"{self.parent.path}.{import_path}"
value = dynamic_import(import_path, import_paths)
top_node = ObjectNode(value, self.module_name)
self.inspect(top_node)
parent = None
if self.parent is not None:
for part in self.parent.path.split("."):
parent = ObjectNode(None, name=part, parent=parent)
module_node = ObjectNode(value, self.module_name, parent=parent)
self.inspect(module_node)
return self.current.module

def inspect(self, node: ObjectNode) -> None:
Expand Down
5 changes: 2 additions & 3 deletions src/griffe/agents/nodes/_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ def alias_target_path(self) -> str | None:
# - but break special cycles coming from builtin modules
# like ast -> _ast -> ast (here we inspect _ast)
# or os -> posix/nt -> os (here we inspect posix/nt)
if self.parent is None:
return None

obj = self.obj
if isinstance(obj, cached_property):
Expand All @@ -326,9 +328,6 @@ def alias_target_path(self) -> str | None:
if not child_module:
return None

if self.parent is None:
return None

if self.parent.is_module:
parent_module = self.parent.obj
else:
Expand Down

0 comments on commit 6a63b37

Please sign in to comment.