python - Grouping function parameters with sphinx - Stack Overflow

admin2025-04-15  0

I want to group the parameters of a function so that, instead of

myfunc(from, until, col_color, col_taste)
    Parameters:   · from First date of the period to be selected.
                  · until Last date of the period to be selected.
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

I want to have

myfunc(from, until, col_color, col_taste)
    Selection parameters:
                  · from First date of the period to be selected.
                  · until Last date of the period to be selected.

    Content parameters:
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

Is there a means to do this?

I tried to write the doc-string for the function as follows:

def myfunc(from, until, col_color, col_taste)
    """
    Gets data from the desires period and returns them as a dataframe.

    Selection parameters:
    :param from: First date of the period to be selected.
    :param until: Last date of the period to be selected.

    Content parameters:
    :param col_color: Whether to include the color column in the
                    output.
    :param col_taste: Whether to include the taste column in the
                    output.

But then, he list of all parameters are printed twice, one below the "Selection parameters" text and another one after the "Content parameters" text.

I want to group the parameters of a function so that, instead of

myfunc(from, until, col_color, col_taste)
    Parameters:   · from First date of the period to be selected.
                  · until Last date of the period to be selected.
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

I want to have

myfunc(from, until, col_color, col_taste)
    Selection parameters:
                  · from First date of the period to be selected.
                  · until Last date of the period to be selected.

    Content parameters:
                  · col_color Whether to include the color column in the
                    output.
                  · col_taste. Whether to include the taste column in the
                    output.

Is there a means to do this?

I tried to write the doc-string for the function as follows:

def myfunc(from, until, col_color, col_taste)
    """
    Gets data from the desires period and returns them as a dataframe.

    Selection parameters:
    :param from: First date of the period to be selected.
    :param until: Last date of the period to be selected.

    Content parameters:
    :param col_color: Whether to include the color column in the
                    output.
    :param col_taste: Whether to include the taste column in the
                    output.

But then, he list of all parameters are printed twice, one below the "Selection parameters" text and another one after the "Content parameters" text.

Share Improve this question asked Feb 4 at 14:18 Antonio SerranoAntonio Serrano 5153 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I now get the desired results. The reason for the parameters being printed twice was not related to the way I grouped them. So, it is ok to do it in the way I have done.

The reason for the parameters being printed twice was that I used two extensions, in the source/conf.py file that serve the same purpose: to write the default values of the function parameters in the output html. The two extensions are: sphinx_autodoc_typehints and sphinxcontrib.default_values. I eliminated the last one, because the former aims to accomplish more additional tasks.

转载请注明原文地址:http://www.anycun.com/QandA/1744713900a86595.html