How to document namedtuple fields in Python?

36 views
Skip to first unread message

Joris van Rantwijk

unread,
Jan 28, 2021, 5:31:21 AM1/28/21
to sphinx-users

Hello,

What is the best way to document namedtuple fields in Python?
We are using the Sphinx autodoc extension to generate API documentation.
Currently, we document namedtuples as follows:

class MyTuple(typing.NamedTuple):
    """This is my named tuple.

    Attributes:
        x: This is the X coordinate.
        y: This is the Y coordinate.
    """
    x: float
    y: float

When processing this with Sphinx 3.4.3, I see two problems:

- Sphinx prints warnings like
C:\defs.py:docstring of qmi.defs.MyTuple.x:1: WARNING: duplicate object description of qmi.defs.MyTuple.x, other instance in generated/qmi.defs, use :noindex: for one of them

- The generated HTML output actually contains two entries for each namedtuple field, one entry containing my explicit documentation "This is the X coordinate", the other entry containing the boilerplate string "Alias for field number 0".

How can I avoid this. Is there a better way of writing the tuple field documentation, or some configuration setting of sphinx.ext.autodoc that I can use ?

Thanks,
Joris.
Reply all
Reply to author
Forward
0 new messages