导入Package类中的方法时,确保使用了完全限定的名称,如Package.Class.method,而不是from Package.Class import method。
在Sphinx的配置文件中加上以下两行,使得Sphinx能够正确地处理pandas中的注解:
autodoc_mock_imports = ['pandas']
numpydoc_show_class_members = False
注意:autodoc_mock_imports用于模拟某些模块,在Sphinx文档构建过程中可以动态地替换实际的模块。因此,在使用这个配置选项时,需要将pandas添加到autodoc_mock_imports,以避免Sphinx在构建文档时尝试导入实际的pandas模块。numpydoc_show_class_members用于决定是否在文档中显示类的成员。在本例中,我们将其设置为False,因为这样可以避免Sphinx尝试在文档中显示pandas中的类成员,从而导致自动文档生成失败。
示例代码:
# my_module.py
import pandas as pd
class MyClass:
    """
    A simple class
    """
    def my_method(self, arg1, arg2):
        """
        A simple method
        
        Parameters
        ----------
        arg1 : int
            The first argument
        arg2 : str
            The second argument
        """
        pass
# conf.py
autodoc_mock_imports = ['pandas']
numpydoc_show_class_members = False
# index.rst
.. automodule:: my_module
   :members:
                    上一篇:AutoSuggest下拉列表在我将鼠标移动到窗口表单组合框中选择项目时自动关闭
                
下一篇:AutoSys - "On No Execution"和"On Ice"之间的区别 AutoSys - "On No Execution"和"On Ice"之间的区别