本文介绍了自动扩展扩展模拟类的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在扩展外部类的类上运行autodoc.

I'm trying to run autodoc over a class that extends an external class.

我使用了模拟,以便接受导入.

I've used mock so that the import is accepted.

为此,我使用了本博客 http://blog.rtwilson.com/how-to-make-your-sphinx-documentation-compile-with-readthedocs-when-you-using-numpy -and-scipy/

For that I used what was described in this blog http://blog.rtwilson.com/how-to-make-your-sphinx-documentation-compile-with-readthedocs-when-youre-using-numpy-and-scipy/

import mock

MOCK_MODULES = ['de', 'de.xyz', 'de.xyz.class_that_is_extended']
for mod_name in MOCK_MODULES:
  sys.modules[mod_name] = mock.Mock()

我尝试记录的python文件如下所示: 从de.xyz导入class_that_is_extended

The python file I try to document looks like this: from de.xyz import class_that_is_extended

class extending_class (class_that_is_extended):
'''
  docstring
'''

运行狮身人面像后的结果是,仅显示类名以及到源的链接.

After running sphinx the result is, that just the class name plus the link to the source is shown.

当我更改"class extended_class(class_that_is_extended)类"行时:到扩展类(对象)类":sphinx/autodoc生成带有文档字符串的文档.

When I change the line "class extending_class (class_that_is_extended):"to "class extending_class (object):" sphinx/autodoc generates the documentation with docstring.

我怎样才能使该类保持原样并仍在文档中获取文档字符串?

How can I leave the class as is and still get the docstring in the documentation?

推荐答案

使用此处发布的方法: Sphinx-doc:automodule:具有模拟导入功能

Using the apporach posted here:Sphinx-doc :automodule: with Mock imports

我刚刚更改了这一行:

sys.modules[mod_name] = mock.Mock()

收件人:

sys.modules[mod_name] = mock.Mock(class_that_is_extended=object)

并从MOCK_MODULES中删除了'de.xyz.class_that_is_extended'

and removed 'de.xyz.class_that_is_extended' from MOCK_MODULES

这篇关于自动扩展扩展模拟类的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:28