Seeking a way to achieve the subject.
I want to create a named tuple
document from a docstring.
sample.py
NamedTuple = namedtuple("NamedTuple", "aaa bbb ccc")
When defining a named tuple
like the one above
The issue of how to write a docstring.
What happens if you use NamedTuple
as it is and make
the document with sphinx
?
.. autoclass:: simplesqlite.sample.NamedTuple
:members:
:undoc-members:
It became as follows. Members are displayed, but there is no amount of information if only the member explanations are automatically output.
Some people had the same challenges.
Adding docstrings to namedtuples in Python? - Stack Overflow http://stackoverflow.com/questions/1606436/adding-docstrings-to-namedtuples-in-python
Multiple methods have been answered.
Let's define a class that inherits namedtuple
and try to write a docstring in the class.
class NamedTupleWithDocstring1(namedtuple("NamedTuple", "aaa bbb ccc")):
"""
hogehoge
"""
If you make
this with sphinx
It would be nice to add the member's explanation to this.
class NamedTupleWithDocstring2(namedtuple("NamedTuple", "aaa bbb ccc")):
"""
hogehoge
.. py:attribute:: aaa
Description of the ``aaa``.
.. py:attribute:: bbb
Description of the ``bbb``.
.. py:attribute:: ccc
Description of the ``ccc``.
"""
Recommended Posts