如何从sphinx-napoleon和numpy样式的文档中获得与默认rst方式相同的输出?

2024-10-05 14:23:07 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我使用非常简单的python文件:

def magic_function(parameter1):
    """
    Do magic with parameter1.

    :param parameter1: The first of all paramters
    :type parameter1: nd_array
    """
    return parameter1

我在参数后面得到类型:

enter image description here

如果我现在和拿破仑一起使用numpy风格:

def magic_function(parameter1):
    """
    Do magic with parameter1.

    Parameters
    ==========
    parameter1: nd_array
        The first of all paramters

    """
    return parameter1

我的结局是这样的

enter image description here

问题似乎是nd_array不是一个有效的类型,这对于默认的斯芬克斯来说似乎不是一个问题,但是对于拿破仑来说这似乎很重要,例如类型int工作得很完美。你知道吗


Tags: ofthe类型returndefwithmagicfunction
1条回答
网友
1楼 · 发布于 2024-10-05 14:23:07

我不确定下面的方法是否适用于nd_array,但我假设它应该适用于内置类型(strlistfloat,等等)。下面是一个对我有用的小例子:

def get_case_id_from_file_name(file_name):
    """ Retrieve case ID from file name.

    Parameters
         
    str file_name
        Name of the test file to retrieve the case ID from.

    Returns
       -
    list
        A list of split file name with case ID in it.
    """
    return file_name.split('_')

输出:

enter image description here

相关问题 更多 >