How would I cross-reference a function generated by autodoc in Sphinx?

You don’t need to add labels. In order to refer to a Python class, method, or other documented object, use the markup provided by the Python domain. For example, the following defines a cross-reference to the mymethod method: :py:meth:`mymodule.MyClass.mymethod` Or even simpler (since the Python domain is the default): :meth:`mymodule.MyClass.mymethod` The documentation of TextWrapper.wrap that … Read more

How to express multiple types for a single parameter or a return value in docstrings that are processed by Sphinx?

Python 3.10 | (pipe, binary or) Union type hint syntax sugar Once you get access, this will be the way to go, it is sweet: def f(i: int|str) -> int|str: if type(i) is str: return int(i) + 1 else: return str(i) The PEP: https://peps.python.org/pep-0604/ Documented at: https://docs.python.org/3.11/library/typing.html#typing.Union Union type; Union[X, Y] is equivalent to X … Read more

Customize sphinxdoc theme

All I wanted is to add ReST strikethrough in my sphinx doc. Here is how I did it: $ cd my-sphinx-dir $ mkdir -p theme/static $ touch theme/theme.conf $ touch theme/static/style.css In theme/theme.conf: [theme] inherit = default stylesheet = style.css pygments_style = pygments.css (this makes it look like the default theme (l. 2)) In theme/static/style.css: … Read more

Keeping the API updated in Sphinx

sphinx-apidoc only needs to be re-run when the module structure of your project changes. If adding, removing, and renaming modules is an uncommon occurrence for you, it may be easiest to just place the rst files under version control and update them by hand. Adding or removing a module only requires changing a few lines … Read more