diff options
author | Pauli Virtanen <pav@iki.fi> | 2013-02-16 16:22:32 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2013-02-16 17:48:32 +0200 |
commit | fd9064f5ee734ffb1dd1f16e7b0f6ce9cfa25df5 (patch) | |
tree | 3886376bc4a36ddbcbc6a15e08ea21fd94aa3426 | |
parent | c5efee88abd79f2338b28267377fe31be7dfa0f4 (diff) | |
download | numpy-fd9064f5ee734ffb1dd1f16e7b0f6ce9cfa25df5.tar.gz |
BUG: numpydoc: fix bugs in attribute docstring extraction + improve presentation
-rw-r--r-- | doc/sphinxext/numpydoc/docscrape.py | 23 | ||||
-rw-r--r-- | doc/sphinxext/numpydoc/docscrape_sphinx.py | 27 |
2 files changed, 34 insertions, 16 deletions
diff --git a/doc/sphinxext/numpydoc/docscrape.py b/doc/sphinxext/numpydoc/docscrape.py index 1e9f6343a..e4bf308b5 100644 --- a/doc/sphinxext/numpydoc/docscrape.py +++ b/doc/sphinxext/numpydoc/docscrape.py @@ -490,12 +490,19 @@ class ClassDoc(NumpyDocString): NumpyDocString.__init__(self, doc) if config.get('show_class_members', True): - if not self['Methods']: - self['Methods'] = [(name, '', '') - for name in sorted(self.methods)] - if not self['Attributes']: - self['Attributes'] = [(name, '', '') - for name in sorted(self.properties)] + def splitlines_x(s): + if not s: + return [] + else: + return s.splitlines() + + for field, items in [('Methods', self.methods), + ('Attributes', self.properties)]: + if not self[field]: + self[field] = [ + (name, '', + splitlines_x(pydoc.getdoc(getattr(self._cls, name)))) + for name in sorted(items)] @property def methods(self): @@ -511,4 +518,6 @@ class ClassDoc(NumpyDocString): if self._cls is None: return [] return [name for name,func in inspect.getmembers(self._cls) - if not name.startswith('_') and func is None] + if not name.startswith('_') and + (func is None or isinstance(func, property) or + inspect.isgetsetdescriptor(func))] diff --git a/doc/sphinxext/numpydoc/docscrape_sphinx.py b/doc/sphinxext/numpydoc/docscrape_sphinx.py index 20e61920f..8b507b30d 100644 --- a/doc/sphinxext/numpydoc/docscrape_sphinx.py +++ b/doc/sphinxext/numpydoc/docscrape_sphinx.py @@ -72,7 +72,16 @@ class SphinxDocString(NumpyDocString): others = [] for param, param_type, desc in self[name]: param = param.strip() - if not self._obj or hasattr(self._obj, param): + + # Check if the referenced member can have a docstring or not + param_obj = getattr(self._obj, param, None) + if not (callable(param_obj) + or isinstance(param_obj, property) + or inspect.isgetsetdescriptor(param_obj)): + param_obj = None + + if param_obj and (pydoc.getdoc(param_obj) or not desc): + # Referenced object has a docstring autosum += [" %s%s" % (prefix, param)] else: others.append((param, param_type, desc)) @@ -82,15 +91,15 @@ class SphinxDocString(NumpyDocString): out += autosum if others: - maxlen_0 = max([len(x[0]) for x in others]) - maxlen_1 = max([len(x[1]) for x in others]) - hdr = "="*maxlen_0 + " " + "="*maxlen_1 + " " + "="*10 - fmt = '%%%ds %%%ds ' % (maxlen_0, maxlen_1) - n_indent = maxlen_0 + maxlen_1 + 4 - out += [hdr] + maxlen_0 = max(3, max([len(x[0]) for x in others])) + hdr = u"="*maxlen_0 + u" " + u"="*10 + fmt = u'%%%ds %%s ' % (maxlen_0,) + out += ['', hdr] for param, param_type, desc in others: - out += [fmt % (param.strip(), param_type)] - out += self._str_indent(desc, n_indent) + desc = u" ".join(x.strip() for x in desc).strip() + if param_type: + desc = "(%s) %s" % (param_type, desc) + out += [fmt % (param.strip(), desc)] out += [hdr] out += [''] return out |