Python模块docs在参数中实例化类

时间:2015-08-07 00:31:10

标签: python python-sphinx

我有一个我正试图用Sphinx记录的课程。包含以下类的模块(仅显示类的第一部分)

class StructureContainer:
    """
    Data structure for describing a collection of Particles
    """

    def __init__(self, ptclC=ParticleContainer()):
       …

包含在我的sphinx文档中,代码如下:

.. automodule:: structureContainer
   :members:
   :show-inheritance:

哪个工作正常。但是ptclC的默认值应该是另一个类'ParticleContainer'的默认构造函数。但是在文档中看起来好像是在文档本身中实例化构造函数(抱歉我不能发布图像)

class structureContainer.StructureContainer(ptclC=<particles.ParticleContainer instance at 0x1071ed710>,

如何将对象实例信息排除在HTML文档之外?

1 个答案:

答案 0 :(得分:0)

So, to elaborate and perhaps fix your problem as well...

def __init__(self, ptclC=None):
     if ptclC is None:        
         ptclC =ParticleContainer()

The reason I am answering this is because I think Sphinx is, correctly, showing that you're instantiating at function definition time.