diff options
Diffstat (limited to 'doc/sphinxext')
-rw-r--r-- | doc/sphinxext/docscrape.py | 13 | ||||
-rw-r--r-- | doc/sphinxext/docscrape_sphinx.py | 11 | ||||
-rw-r--r-- | doc/sphinxext/numpydoc.py | 2 |
3 files changed, 17 insertions, 9 deletions
diff --git a/doc/sphinxext/docscrape.py b/doc/sphinxext/docscrape.py index 904270a52..f374b3ddc 100644 --- a/doc/sphinxext/docscrape.py +++ b/doc/sphinxext/docscrape.py @@ -406,11 +406,13 @@ def header(text, style='-'): class FunctionDoc(NumpyDocString): - def __init__(self, func, role='func'): + def __init__(self, func, role='func', doc=None): self._f = func self._role = role # e.g. "func" or "meth" + if doc is None: + doc = inspect.getdoc(func) or '' try: - NumpyDocString.__init__(self,inspect.getdoc(func) or '') + NumpyDocString.__init__(self, doc) except ValueError, e: print '*'*78 print "ERROR: '%s' while parsing `%s`" % (e, self._f) @@ -459,7 +461,7 @@ class FunctionDoc(NumpyDocString): class ClassDoc(NumpyDocString): - def __init__(self,cls,modulename='',func_doc=FunctionDoc): + def __init__(self,cls,modulename='',func_doc=FunctionDoc,doc=None): if not inspect.isclass(cls): raise ValueError("Initialise using a class. Got %r" % cls) self._cls = cls @@ -470,7 +472,10 @@ class ClassDoc(NumpyDocString): self._name = cls.__name__ self._func_doc = func_doc - NumpyDocString.__init__(self, pydoc.getdoc(cls)) + if doc is None: + doc = pydoc.getdoc(cls) + + NumpyDocString.__init__(self, doc) @property def methods(self): diff --git a/doc/sphinxext/docscrape_sphinx.py b/doc/sphinxext/docscrape_sphinx.py index d431ecd3f..77ed271b0 100644 --- a/doc/sphinxext/docscrape_sphinx.py +++ b/doc/sphinxext/docscrape_sphinx.py @@ -115,7 +115,7 @@ class SphinxFunctionDoc(SphinxDocString, FunctionDoc): class SphinxClassDoc(SphinxDocString, ClassDoc): pass -def get_doc_object(obj, what=None): +def get_doc_object(obj, what=None, doc=None): if what is None: if inspect.isclass(obj): what = 'class' @@ -126,8 +126,11 @@ def get_doc_object(obj, what=None): else: what = 'object' if what == 'class': - return SphinxClassDoc(obj, '', func_doc=SphinxFunctionDoc) + return SphinxClassDoc(obj, '', func_doc=SphinxFunctionDoc, doc=doc) elif what in ('function', 'method'): - return SphinxFunctionDoc(obj, '') + return SphinxFunctionDoc(obj, '', doc=doc) else: - return SphinxDocString(pydoc.getdoc(obj)) + if doc is None: + doc = pydoc.getdoc(obj) + return SphinxDocString(doc) + diff --git a/doc/sphinxext/numpydoc.py b/doc/sphinxext/numpydoc.py index 21a5ae5ec..ff6c44c53 100644 --- a/doc/sphinxext/numpydoc.py +++ b/doc/sphinxext/numpydoc.py @@ -28,7 +28,7 @@ def mangle_docstrings(app, what, name, obj, options, lines, re.I|re.S) lines[:] = title_re.sub('', "\n".join(lines)).split("\n") else: - doc = get_doc_object(obj, what) + doc = get_doc_object(obj, what, "\n".join(lines)) lines[:] = str(doc).split("\n") if app.config.numpydoc_edit_link and hasattr(obj, '__name__') and \ |