Imagine I want to import functions or classes directly from the top-level package, i. e. my_package.PublicClass. To keep an internal structure, I don't want to dump everything into __init__.py but rather split the functionality in a _private_module.py and simply import it. From the python perspective this works as intended, but I face problem with the documentation. TL;DR Is there a way to alias the autogenerated link from my_package._private_module.PublicClass to my_package.PublicClass?
---
I've created a
sample repository for my problem. Still, for completeness, I include the important parts here.
Consider the following python package:
my_package/
├── __init__.py
└── _private_module.py
with the following content:
from ._private_module import *
and
__all__ = ["PublicClass", "PublicSubclass"]
class PublicClass:
pass
class PublicSubclass(PublicClass):
""":class:`my_package.PublicClass`"""
pass
The documentation is built with the following
.. automodule:: my_package
.. autoclass:: PublicClass
.. autoclass:: PublicSubclass
:show-inheritance:
As you can see in the
built documentation the reference in the doc string works fine. The inheritance on the other hand references
my_package._private_module.PublicClass which is not only misleading, but also breaks the link to
my_package.PublicClass. Thus, I repeat the question from above: Is there a way to replace the autogenerated link from
my_package._private_module.PublicClass with links
my_package.PublicClass?