I am documenting code in Sphinx that resembles this:
class ParentClass(object):
def __init__(self):
pass
def generic_fun(self):
"""Call this function using /run/ParentClass/generic_fun()"""
do_stuff()
class ChildClass(ParentClass):
def specific_fun(self):
"""Call this function using /run/ChildClass/specific_fun()"""
do_other_stuff()
I added the :inherited-members to the ChildClass documentation, so I have statements in there like "Call this function using /run/ParentClass/generic_fun()".
Is there a way I can put something in the docstrings like <class_name> that Sphinx will replace with the actual class that it’s documenting?
I would like to have the code look like:
class ParentClass(object):
def __init__(self):
pass
def generic_fun(self):
"""Call this function using /run/<class_name>/generic_fun()"""
do_stuff()
So in the ChildClass section, the Sphinx documentation would read "(…) using /run/ChildClass/generic_fun()(…)" and the ParentClass section would read "(…) using /run/ParentClass/generic_fun()(…)"?
Ideally I’d like to have the documentation on the same page, so the replacement string would be different for different sections.
I figured out a way to do this while looking at something else.
There are functions autodoc will call before printing the message. I added this code to my conf.py file:
I want to use the | token, but they are reserved for global substitutions. I got around that by putting the following line my rst file (so the code substitutes |class| for |class|):