Skip to content

Commit 6a63b37

Browse files
committed
fix: Fix detecting whether an object should be an alias during inspection
Issue #180: #180
1 parent d34a3ba commit 6a63b37

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/griffe/agents/inspector.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ def get_module(self, import_paths: Sequence[str | Path] | None = None) -> Module
174174
if self.parent is not None:
175175
import_path = f"{self.parent.path}.{import_path}"
176176
value = dynamic_import(import_path, import_paths)
177-
top_node = ObjectNode(value, self.module_name)
178-
self.inspect(top_node)
177+
parent = None
178+
if self.parent is not None:
179+
for part in self.parent.path.split("."):
180+
parent = ObjectNode(None, name=part, parent=parent)
181+
module_node = ObjectNode(value, self.module_name, parent=parent)
182+
self.inspect(module_node)
179183
return self.current.module
180184

181185
def inspect(self, node: ObjectNode) -> None:

src/griffe/agents/nodes/_runtime.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ def alias_target_path(self) -> str | None:
314314
# - but break special cycles coming from builtin modules
315315
# like ast -> _ast -> ast (here we inspect _ast)
316316
# or os -> posix/nt -> os (here we inspect posix/nt)
317+
if self.parent is None:
318+
return None
317319

318320
obj = self.obj
319321
if isinstance(obj, cached_property):
@@ -326,9 +328,6 @@ def alias_target_path(self) -> str | None:
326328
if not child_module:
327329
return None
328330

329-
if self.parent is None:
330-
return None
331-
332331
if self.parent.is_module:
333332
parent_module = self.parent.obj
334333
else:

0 commit comments

Comments
 (0)