bug: Erroneous detection of cyclic alias
Description of the bug
In a library with the following namespaced module structure
├── index.py
├── __init__.py
and the following content of the init
from .index import (
index,
)
I get the following error when generating docs using mkdocstrings:
File "/usr/local/venv/lib/python3.11/site-packages/griffe/_internal/models.py", line 1505, in members
final_target = self.final_target
^^^^^^^^^^^^^^^^^
File "/usr/local/venv/lib/python3.11/site-packages/griffe/_internal/models.py", line 2104, in final_target
target = target.target # type: ignore[assignment]
^^^^^^^^^^^^^
File "/usr/local/venv/lib/python3.11/site-packages/griffe/_internal/models.py", line 2069, in target
self.resolve_target()
File "/usr/local/venv/lib/python3.11/site-packages/griffe/_internal/models.py", line 2133, in resolve_target
raise CyclicAliasError([self.target_path])
griffe._internal.exceptions.CyclicAliasError: Cyclic aliases detected:
my_library.index.index
Expected behavior
Of course one can argue that simply renaming the module or the function imported from the module avoids this issue. However, this is valid and idiomatic python and I would have expected that the api reference generation works.
Thanks for the report. It seems incomplete though. From what you wrote I gather you have an index function (or any other object of the same name) within the index.py module, right? And then you import it within the top-level __init__.py module. The end result is that you have both pkg.index the module, and pkg.index the function. This isn't supported by Griffe, see https://mkdocstrings.github.io/griffe/guide/users/recommendations/python-code/#avoid-member-submodule-name-shadowing. This shouldn't trigger a cyclic alias error though, only give precedence to the module. If you provide a minimal reproduction example I can look into fixing this cyclic alias error 🙂