@@ -79,21 +79,74 @@ def _str_returns(self, name='Returns'):
79
79
out += ['' ]
80
80
return out
81
81
82
- def _str_param_list (self , name ):
82
+ def _str_param_list (self , name , fake_autosummary = False ):
83
83
out = []
84
84
if self [name ]:
85
+ if fake_autosummary :
86
+ prefix = getattr (self , '_name' , '' )
87
+ if prefix :
88
+ autosum_prefix = '~%s.' % prefix
89
+ link_prefix = '%s.' % prefix
90
+ else :
91
+ autosum_prefix = ''
92
+ link_prefix = ''
93
+ autosum = []
94
+
85
95
out += self ._str_field_list (name )
86
96
out += ['' ]
87
97
for param , param_type , desc in self [name ]:
98
+ param = param .strip ()
99
+
100
+ display_param = '**%s**' % param
101
+
102
+ if fake_autosummary :
103
+ param_obj = getattr (self ._obj , param , None )
104
+ if not (callable (param_obj )
105
+ or isinstance (param_obj , property )
106
+ or inspect .isgetsetdescriptor (param_obj )):
107
+ param_obj = None
108
+ obj_doc = pydoc .getdoc (param_obj )
109
+
110
+ if param_obj and (obj_doc or not desc ):
111
+ # Referenced object has a docstring
112
+ autosum += [" %s%s" % (autosum_prefix , param )]
113
+ # TODO: add signature to display as in autosummary
114
+ # Difficult because autosummary's processing
115
+ # involves sphinx's plugin mechanism, for
116
+ # directives only
117
+ display_param = ':obj:`%s <%s%s>`' % (param ,
118
+ link_prefix ,
119
+ param )
120
+ if obj_doc :
121
+ # Overwrite desc. Take summary logic of autosummary
122
+ desc = re .split ('\n \s*\n ' , obj_doc .strip (), 1 )[0 ]
123
+ # XXX: Should this have DOTALL?
124
+ # It does not in autosummary
125
+ m = re .search (r"^([A-Z].*?\.)(?:\s|$)" , desc )
126
+ if m :
127
+ desc = m .group (1 ).strip ()
128
+ else :
129
+ desc = desc .partition ('\n ' )[0 ]
130
+ desc = desc .split ('\n ' )
131
+
88
132
if param_type :
89
- out += self ._str_indent (['**%s** : %s' % (param . strip () ,
90
- param_type )])
133
+ out += self ._str_indent (['%s : %s' % (display_param ,
134
+ param_type )])
91
135
else :
92
- out += self ._str_indent (['**%s**' % param . strip () ])
136
+ out += self ._str_indent ([display_param ])
93
137
if desc :
94
138
out += ['' ]
95
139
out += self ._str_indent (desc , 8 )
96
140
out += ['' ]
141
+
142
+ if fake_autosummary and autosum :
143
+ if self .class_members_toctree :
144
+ autosum .insert (0 , ' :toctree:' )
145
+ autosum .insert (0 , '.. autosummary::' )
146
+ out += ['..' , ' HACK to make autogen generate docs:' ]
147
+ out += self ._str_indent (autosum , 4 )
148
+ out += ['' ]
149
+
97
150
return out
98
151
99
152
@property
@@ -250,7 +303,8 @@ def __str__(self, indent=0, func_role="obj"):
250
303
'notes' : self ._str_section ('Notes' ),
251
304
'references' : self ._str_references (),
252
305
'examples' : self ._str_examples (),
253
- 'attributes' : self ._str_member_list ('Attributes' ),
306
+ 'attributes' : self ._str_param_list ('Attributes' ,
307
+ fake_autosummary = True ),
254
308
'methods' : self ._str_member_list ('Methods' ),
255
309
}
256
310
ns = dict ((k , '\n ' .join (v )) for k , v in ns .items ())
0 commit comments