属性的狮身人面像值报告为“无” [英] Sphinx values for attributes reported as None

查看:77
本文介绍了属性的狮身人面像值报告为“无”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Sphinx自动文档来记录一个类时,总是报告属性的值(因为它说应该此处,在#437下),但始终为 =无

When I use Sphinx autodoc to document a class, the values for the attributes are always reported, (as it says it should here, under #437) but always as "= None"

Attribute = None
    Some Documentation

我将其包括在内

.. autoclass:: core.SomeClass
   :members:

我的代码如下

class SomeClass(object):
    def __init__(self):
        self.attribute = "value" #: Some Documentation

有没有办法要么使 = None报告真实值,要么使其消失?

Is there a way to either make the "= None" report the real value, or make it disappear?

推荐答案

我很确定这是必须要做的您的属性是实例属性。在实例化该类之前,它不会获得值。 Sphinx导入模块是为了检查它们,但它不会实例化任何类。

I am pretty sure this has to do with the fact that your attribute is an instance attribute. It does not get a value until the class is instantiated. Sphinx imports modules in order to inspect them, but it does not instantiate any classes.

因此Sphinx不知道实际值,而输出。我不认为您可以轻松解决它(但我想,如果您准备打补丁Sphinx源代码,那么一切皆有可能...)。如果您不喜欢这样做,则可以在类的文档字符串中记录属性。

So the "real value" is not known by Sphinx, and None is output. I don't think you can make it go away easily (but I suppose anything is possible if you are prepared to patch the Sphinx source code...). If you don't like this, you could document attributes in the docstring of the class instead.

使用相同标记方案记录的类属性( )确实将其值显示在渲染的输出中。但是没有明确的迹象表明读者可以轻松区分类属性和实例属性。也许Sphinx在这里可能会更有帮助。

Class attributes that are documented using the same markup scheme (described here) do get their values displayed in the rendered output. But there is no clear indication that makes it easy for the reader to distinguish between class and instance attributes. Maybe Sphinx could be a little more helpful here.

这篇关于属性的狮身人面像值报告为“无”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆