【问题标题】:pycharm quick documentation (CTRL+Q) not loading local documented filepycharm 快速文档(CTRL+Q)不加载本地文档文件
【发布时间】:2016-05-19 13:33:27
【问题描述】:

我正在使用 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 格式来编写文档。

谢谢!

【问题讨论】:

    标签: pycharm code-documentation


    【解决方案1】:

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

    【讨论】:

    • 非常感谢!有什么方法可以改变 pycharm 的期望吗?另外,使用您发布的格式,有什么方法可以指示参数和返回值的类型?
    • 他们提供了有关此here 的详细信息,尽管我不确定您将如何更改它的预期。我有自己的约定,通常您仍然可以看到您输入的任何内容常规文本,所以试着弄乱一下。
    【解决方案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

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 2017-09-13
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多