Ger*_*rer 8 python-sphinx python-3.5
我正在使用Sphinx(make HTML)从其函数的reStructuredText文档字符串自动生成Python 3模块的HTML文档.到目前为止,生成的HTML文档看起来很好,但函数签名的参数类型(在源代码中作为PEP484类型提示给出)未正确显示.
例如,这是我的一个函数的Sphinx生成的HTML文档的一些示例输出:
static parse_from_file(filename: str) ? list
    Parses stuff from a text file.
    Parameters:  filename – the filepath of a textfile to be parsed
    Returns:     list of parsed elements
这就是我期望的样子:
static parse_from_file(filename)
    Parses stuff from a text file.
    Parameters:  filename (str) – the filepath of a textfile to be parsed
    Returns:     list of parsed elements
    Return type: list
这就是Python代码的实际外观:
def parse_from_file(filename: str) -> list:
    """Parses stuff from a text file.
    :param filename: the filepath of a textfile to be parsed
    :returns: list of parsed elements
    """
    return []
如何让Sphinx正确显示Python 3类型的提示?
Bře*_*jek 10
有autodoc_typehints变数。从 3.0 版开始,您可以将其设置为将'description'类型提示显示为函数或方法的内容,并将它们从签名中删除。
所以只需将此行添加到您的conf.py:
autodoc_typehints = "description"
| 归档时间: | 
 | 
| 查看次数: | 2472 次 | 
| 最近记录: |