Documenting class attributes with type annotations

I do not think you can put an Attribute section inside of your docstring to get your desired results. I tried giving each attribute a doc comment and specified the type and desired comment. class DataHolder: “”” Class to hold some data Each attribute needs its own doc comment with its type “”” #: bool: … Read more

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

Sphinx error: Unknown directive type “automodule” or “autoclass”

The same thing happened to me! To fix it, go to the line in conf.py that says something like this: extensions = [‘sphinx.ext.todo’, ‘sphinx.ext.viewcode’] Yours will probably look different. Anyway, add ‘sphinx.ext.autodoc’ to the list. e.g. extensions = [‘sphinx.ext.todo’, ‘sphinx.ext.viewcode’, ‘sphinx.ext.autodoc’] If it was: extensions = [] then you’d change it to: extensions = [‘sphinx.ext.autodoc’] … Read more

How to use Sphinx’s autodoc to document a class’s __init__(self) method?

Here are three alternatives: To ensure that __init__() is always documented, you can use autodoc-skip-member in conf.py. Like this: def skip(app, what, name, obj, would_skip, options): if name == “__init__”: return False return would_skip def setup(app): app.connect(“autodoc-skip-member”, skip) This explicitly defines __init__ not to be skipped (which it is by default). This configuration is specified … Read more

What is the correct way to document a **kwargs parameter?

After finding this question I settled on the following, which is valid Sphinx and works fairly well: def some_function(first, second=”two”, **kwargs): r”””Fetches and returns this thing :param first: The first parameter :type first: “int“ :param second: The second parameter :type second: “str“ :param \**kwargs: See below :Keyword Arguments: * *extra* (“list“) — Extra stuff * … Read more

Sphinx autodoc is not automatic enough

You can check this script that I’ve made. I think it can help you. This script parses a directory tree looking for python modules and packages and creates ReST files appropriately to create code documentation with Sphinx. It also creates a modules index. UPDATE This script is now part of Sphinx 1.1 as apidoc.