I want to display a class attribute (which is a class) with my document

class Parameters(dict):
     """ Some doc here """
     pass

class System(object):
     Parameter = Parameters
     """ The default parameters attribute builder """

     def __init__(self):
         self.parameters = self.Parameters()

The problem is that I make autoclasssystems with a sphinx, the document parameter will not be what I wrote below Parameter = Parameters, but it will be a complete document of the Parameter class. I do not want this, it is too dirty and does not correspond to what my .Parameters attribute is valid (can be a Parameters class, as well as a function, or dict(a=0,b=1).copyetc.).

System
======
.. autoclass:: system.System
    :members: __init__,Parameters

The only way I found is to first set the “No” parameter and change it during initialization, but this is not convenient for other reasons.

class System(object):
    Parameter = None
    """ The default parameters attribute builder """

 def __init__(self):
     if self.Parameters is None:
         self.Parameters = Parameters
     self.parameters = self.Parameters()
+4
source share
1 answer

?

class Parameters(dict):
    pass

class System(object):

    def __init__(self, Parameters):
        self.parameters = Parameters


parameters = Parameters()
parameters['x'] = '3.14'
parameters['y'] = '1.618'

system = System(parameters)

print(system.parameters)

{'y': '1.618', 'x': '3.14'}
+1

Source: https://habr.com/ru/post/1679065/


All Articles