@@ -420,22 +420,20 @@ def _keep_object(name: str, filters: Sequence[tuple[Pattern, bool]]) -> bool:
420420
421421
422422def _parents (obj : Alias ) -> set [str ]:
423- parent : Object | Alias = obj .parent
424- parents = {obj .path , parent .path }
425- if parent .is_alias :
426- parents .add (parent .final_target .path )
427- while parent .parent :
428- parent = parent .parent
423+ parents = {obj .path }
424+ parent = obj .parent
425+ while parent is not None :
429426 parents .add (parent .path )
430- if parent . is_alias :
427+ if isinstance ( parent , Alias ) :
431428 parents .add (parent .final_target .path )
429+ parent = parent .parent
432430 return parents
433431
434432
435433def _remove_cycles (objects : list [Object | Alias ]) -> Iterator [Object | Alias ]:
436434 suppress_errors = suppress (AliasResolutionError , CyclicAliasError )
437435 for obj in objects :
438- if obj . is_alias :
436+ if isinstance ( obj , Alias ) :
439437 with suppress_errors :
440438 if obj .final_target .path in _parents (obj ):
441439 continue
@@ -784,6 +782,8 @@ def expand_identifier(self, identifier: str) -> str:
784782 obj = self .current_object
785783 while identifier and identifier [0 ] == "." :
786784 identifier = identifier [1 :]
785+ if obj .parent is None :
786+ break
787787 obj = obj .parent
788788 identifier = f"{ obj .path } .{ identifier } " if identifier else obj .path
789789
@@ -814,12 +814,13 @@ def get_context(self) -> AutorefsHookInterface.Context:
814814 "module" : "mod" ,
815815 }.get (self .current_object .kind .value .lower (), "obj" )
816816 origin = self .current_object .path
817- try :
818- filepath = self .current_object .docstring .parent .filepath
819- lineno = self .current_object .docstring .lineno or 0
820- except AttributeError :
817+ docstring = self .current_object .docstring
818+ if docstring is None or docstring .parent is None :
821819 filepath = self .current_object .filepath
822820 lineno = 0
821+ else :
822+ filepath = docstring .parent .filepath
823+ lineno = docstring .lineno or 0
823824
824825 return AutorefsHookInterface .Context (
825826 domain = "py" ,
0 commit comments