I have a class factory that generates a class with a function bound to another class. When a class inherits from the generated class it gains the appropriate function. Now I want to document the generated class' function else one would have to inspect the class factory to see what the function does or the class factory's documentation must describe all of the generated class' functions.
Class factory:
def greeter(name):
"""Generate a greeter for the given name."""
class Greeter(object):
def greet(self):
print('Hello {}.'.format(name))
greet.__doc__ = "Greet someone by the name of {!r}".format(name)
return Greeter
It's usage:
class GreetArthur(greeter('Arthur')):
pass
GreetArthur().greet() # Prints 'Hello Arthur.'
Now when this gets documented by Sphinx it is clear that GreetArthur
inherits from Greeter
, but Greeter
is never documented because it's generated. From the documentation it is thus not clear that GreetArthur
has a function greet
.
greeter(name)
Generate a greeter for the given name.
class GreetArthur
Bases: Greeter
Desired result:
greeter(name)
Generate a greeter for the given name.
class GreetArthur
Bases: Greeter
greet()
Greet someone by the name of 'Arthur'.
Looks like the :inherited-members:
does the trick. It works both for :automodule:
and :autoclass:
.
.. automodule:: greet
:members:
:inherited-members:
or
.. autoclass:: greet.GreetArthur
:members:
:inherited-members:
This will result in:
class greet.GreetArthur
greet()
Greet someone by the name of 'Arthur'.