pycharm 快速文档 (CTRL+Q) 未加载本地文档文件

pycharm quick documentation (CTRL+Q) not loading local documented file

我正在使用 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 时弹出的快速文档 window 中看到它。但是,情况并非如此. window 仅显示类型推断:

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

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

我找到了这个 post:Documenting Python parameters in docstring using PyCharm。但是希望使用NumPy格式来编写文档。

谢谢!

似乎每个人都对 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

首先,进入设置面板:File -> Settings。然后搜索docstring,将Docstring格式改成这样:

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

访问 会有帮助。

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