pycharm快速文档(CTRL + Q)没有加载本地文档

时间:2016-05-19 13:33:27

标签: pycharm code-documentation

我正在使用pycharm 2016.1。

我的功能记录如下:

def extract_filename(filepath, ext=None):
    """
    This function returns the filename from a complete filepath including its extension.
    If ext is set to an extension it is removed from the filename.


    Parameters
    ----------
    filepath : string
    ext : string

    Returns
    -------
    string
    """

    if ext[0] != ".":
        ext = "." + ext

    filename = filepath.split("/")[-1]
    if ext is not None:
        filename = filename.split(ext)[0]

    return filename

我原本希望一旦这个文档到位,我就可以在按下CTRL + Q时弹出的快速文档窗口中看到它。但是,情况并非如此。该窗口仅显示类型推断:

def extract_filename(filepath, ext=None) Inferred type: (filepath: Union[str, unicode], ext: Union[str, unicode]) -> Union[str, unicode]

我在这里缺少什么?我认为通过记录我的函数,它的描述和参数会显示出很好的格式化。

我发现了这篇文章:Documenting Python parameters in docstring using PyCharm。但是希望使用NumPy格式来编写文档。

谢谢!

2 个答案:

答案 0 :(得分:2)

似乎每个人对Docstrings都有不同的标准,并且考虑到PEP-257中的文档,我可以看到为什么你会用这种方式格式化。 PyCharm更喜欢这个:

def function(arg1, arg2, ..., argn):
    """

    Description of the function and what it returns in an active tone.

    :param arg1: What the argument represents.
    ...
    :param argn: What the argument represents.

    :return: The meaning of the return value 
    """

当应用于您的代码时,它看起来像:

def extract_filename(filepath, ext=None):
   """ 

   Return the file name from a complete file path including its extension.
   If ext is set to an extension, remove it from the file name.

    :param  filepath: The full path to the file in question.
    :param ext: The extension for the file.

    :return: The filename from filepath including its extension. 
    """
    if ext[0] != ".":
        ext = "." + ext

    filename = filepath.split("/")[-1]
    if ext is not None:
        filename = filename.split(ext)[0]

    return filename

答案 1 :(得分:2)

首先,进入设置面板:File -> Settings。然后搜索docstring,并以这种方式更改Docstring格式:

Tools> Python Integrated Tools> Docstrings> Docstring format> NumPy

访问https://stackoverflow.com/a/24385103/6324442会有所帮助。

其他一些文档:http://www.sphinx-doc.org/en/stable/ext/napoleon.html