简体   繁体   English

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

[英]How to get the same output from sphinx napoleon and numpy style docs as with the default rst way?

If I take the very simple python file:如果我采用非常简单的python文件:

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

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

I get the type right after the parameter:我在参数之后立即得到类型:

在此处输入图片说明

If I now use numpy style together with napoleon:如果我现在将 numpy 样式与拿破仑一起使用:

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

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

    """
    return parameter1

I end up with this ugly setup我最终得到了这个丑陋的设置

在此处输入图片说明

The issue seems to be that nd_array is not a valid type which for the default sphinx does not seem to be a problem, but for napoleon this seems to matter, as for example type int works perfectly.问题似乎是nd_array不是一个有效的类型,对于默认的 sphinx 似乎不是问题,但对于拿破仑来说,这似乎很重要,例如类型int工作得很好。

I am not sure if the following would work for nd_array , but I assume it should as it works for built-in types ( str , list , float , etc.).我不确定以下内容是否适用于nd_array ,但我认为它应该适用于内置类型( strlistfloat等)。 Here is a small example of what works for me:这是一个对我有用的小例子:

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('_')

Output:输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM