From 356305f69664c1d955f4dbf7c865cb4f553488fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Sat, 10 Feb 2024 14:59:07 +0100 Subject: [PATCH] fix: Do not create aliases pointing to themselves --- src/griffe/agents/visitor.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/griffe/agents/visitor.py b/src/griffe/agents/visitor.py index fd78e208..7884e841 100644 --- a/src/griffe/agents/visitor.py +++ b/src/griffe/agents/visitor.py @@ -536,16 +536,20 @@ def visit_importfrom(self, node: ast.ImportFrom) -> None: else: alias_name = name.asname or name.name self.current.imports[alias_name] = alias_path - self.current.set_member( - alias_name, - Alias( + # Do not create aliases pointing to themselves (it happens with + # `from package.current_module import Thing as Thing` or + # `from . import thing as thing`). + if alias_path != f"{self.current.path}.{alias_name}": + self.current.set_member( alias_name, - alias_path, - lineno=node.lineno, - endlineno=node.end_lineno, - runtime=not self.type_guarded, - ), - ) + Alias( + alias_name, + alias_path, + lineno=node.lineno, + endlineno=node.end_lineno, + runtime=not self.type_guarded, + ), + ) def handle_attribute( self,