使用Python返回类型注释中断automodule
我正试图用Sphinx记录我的Python3代码。下面是我的示例文件:使用Python返回类型注释中断automodule,python,python-sphinx,Python,Python Sphinx,我正试图用Sphinx记录我的Python3代码。下面是我的示例文件: class MyClass: """ Class description """ def get_name(self) -> str: """ Returns the name of this object as a string. """ return "Jim" 其中一个.rst文件中的指令是: .. autocla
class MyClass:
"""
Class description
"""
def get_name(self) -> str:
"""
Returns the name of this object as a string.
"""
return "Jim"
其中一个.rst文件中的指令是:
.. autoclass:: my_class.MyClass
:members:
但是当我运行sphinxbuild-bhtml-d\u build/doctrees时_build/html
(版本1.1.3),类型注释->
中断:
def command_name(self) -> str:
^
SyntaxError: invalid syntax
如何让Sphinx识别类型注释
编辑:我的python3版本是3.2.3。虽然automodule可能无法识别python3注释,但构建不应中断使用它们。我的案例中的问题是Sphinx使用了我的python2.7解释器:
SyntaxError: invalid syntax
Traceback (most recent call last):on_osdp_messages
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
这可能意味着您安装了错误版本的Sphinx。请参阅(我需要使用不同的Debian软件包)。我想您需要我,如果可能的话,我希望避免扩展。此外,该模块需要3.3+。从文档来看,您似乎需要扩展来完成您想要的任务。我认为升级到Python3.4不会有什么坏处。