[PYTHON] How to write a docstring to create a named tuple document with sphinx

Seeking a way to achieve the subject.

Thing you want to do

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.

Trial 1

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.

ss_0.png

Trial 2

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

ss_1.png

It would be nice to add the member's explanation to this.

Last

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``.
    """

ss_2.png

Recommended Posts

How to write a docstring to create a named tuple document with sphinx
How to write a named tuple document in 2020
How to output a document in pdf format with Sphinx
How to create a submenu with the [Blender] plugin
[Python] How to write a docstring that conforms to PEP8
[Python] How to create a 2D histogram with Matplotlib
How to put a hyperlink to "file: // hogehoge" with sphinx-> pdf
How to create a flow mesh around a cylinder with snappyHexMesh
How to write a Python class
How to create a Conda package
How to create a virtual bridge
How to create a config file
How to create a heatmap with an arbitrary domain in Python
How to create a label (mask) for segmentation with labelme (semantic segmentation mask)
How to create a serverless machine learning API with AWS Lambda
How to create a clone from Github
How to build a sphinx translation environment
How to create a git clone folder
Qiita (1) How to write a code name
How to add a package with PyCharm
How to write Python document comments (Docstrings)
Automatic document generation from docstring with sphinx
How to create a repository from media
Think about how to write a filter with the Shotgun API-Contact Versions
3. Natural language processing with Python 1-2. How to create a corpus: Aozora Bunko
How to create sample CSV data with hypothesis
How to read a CSV file with Python 2/3
How to send a message to LINE with curl
How to create a Python virtual environment (venv)
How to draw a 2-axis graph with pyplot
How to create a function object from a string
How to develop a cart app with Django
How to create a JSON file in Python
How to make a dictionary with a hierarchical structure.
Steps to create a Twitter bot with python
How to write a ShellScript Bash for statement
How to create a shortcut command for LINUX
[Note] How to create a Ruby development environment
How to create a Kivy 1-line input box
How to create a Rest Api in Django
[Go] How to write or call a function
I want to write to a file with Python
How to write a ShellScript bash case statement
[Note] How to create a Mac development environment
How to create random numbers with NumPy's random module
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
Read the Python-Markdown source: How to create a parser
I tried to create a table only with Django
How to write a GUI using the maya command
[Python] How to draw a line graph with Matplotlib
Try to dynamically create a Checkbutton with Python's Tkinter
How to convert a class object to a dictionary with SQLAlchemy
How to make a shooting game with toio (Part 1)
[Go] How to create a custom error for Sentry
How to write a list / dictionary type of Python3
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
How to create a local repository for Linux OS
[Python] A memo to write CSV vertically with Pandas
I want to manually create a legend with matplotlib
A program to write Lattice Hinge with Rhinoceros with Python
How to create a simple TCP server / client script