'Function appears two times in Sphinx autodoc generated documentation

Background information

I generate documentation from docstrings via Sphinx autodoc. There is a function mypackage.mypackage.foo() located in source file mypackage/mypackage.py. It is imported implicite in the __init__.py, so the user can it use as mypackage.foo().

I do manipulate Sphinx autodoc that it generates the docu for foo() respecting they way it is imported. This works.

The problem

The docu about foo() is generated twice; once as mypackage.foo() and once as mypackage.mypackage.foo().

enter image description here

Details

This is the structure of the project:

mypackage
├── a.py
├── __init__.py
└── mypackage.py

The __init__.py does the import and then manipulates the __all__ variable:

from .mypackage import *
__all__ = ['foo']  # for alternative see: https://stackoverflow.com/a/66996523/4865723

And the mypackage/mypackage.py defines foo().

Because of that I can do things like that:

import mypackage
mypackage.foo()

Related questions and answers

Here are questions and answers that took me to the current "part solution". Where mypackage.foo() appears as expected in the documentation but mypackage.mypackage.foo() does not disappear.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source