I'd like to document my class inheriting from a base, both of which are inside a submodule of a larger package. This package imports the classes to the very top level for a better user experience. For that reason I've also made my documentation on that level. Here's the gist of my situation.
# Directory structure
package
__init__.py
sub.py
# sub.py
class Foo:
pass
class Bar(Foo):
pass
# __init__.py
from .sub import Foo, Bar
# Some documentation file
.. currentmodule:: package
.. autoclass:: Foo
.. autoclass:: Bar
:show-inheritance:
Other references to those classes work fine, functioning well with the package.Foo
references instead of package.sub.Foo
. But the show-inheritance
option of autoclass
displays the original path, along with a broken link. Moving the classes to __init__.py
restores the link.
How could I produce a working link? As a bonus I'd like to have the shorter name as is in the class name already.
This is a related question, whose solution I tried out. Modifying the __module__
attribute of those classes works.
# __init__.py
Foo.__module__ = 'package'
Bar.__module__ = 'package'
However, I doubt the optimal solution is to do this manually for every class I've defined, most of which have some kind of inheritance going on.