summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py50
1 files changed, 30 insertions, 20 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index cf87a1c2e..7c2f35f4e 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -481,14 +481,15 @@ class Documenter(object):
domain = getattr(self, 'domain', 'py')
directive = getattr(self, 'directivetype', self.objtype)
name = self.format_name()
+ sourcename = self.get_sourcename()
self.add_line(u'.. %s:%s:: %s%s' % (domain, directive, name, sig),
- '<autodoc>')
+ sourcename)
if self.options.noindex:
- self.add_line(u' :noindex:', '<autodoc>')
+ self.add_line(u' :noindex:', sourcename)
if self.objpath:
# Be explicit about the module, this is necessary since .. class::
# etc. don't support a prepended module name
- self.add_line(u' :module: %s' % self.modname, '<autodoc>')
+ self.add_line(u' :module: %s' % self.modname, sourcename)
def get_doc(self, encoding=None, ignore=1):
"""Decode and return lines of the docstring(s) for the object."""
@@ -514,9 +515,7 @@ class Documenter(object):
for line in docstringlines:
yield line
- def add_content(self, more_content, no_docstring=False):
- """Add content from docstrings, attribute documentation and user."""
- # set sourcename and add content from attribute documentation
+ def get_sourcename(self):
if self.analyzer:
# prevent encoding errors when the file name is non-ASCII
if not isinstance(self.analyzer.srcname, text_type):
@@ -524,8 +523,14 @@ class Documenter(object):
sys.getfilesystemencoding(), 'replace')
else:
filename = self.analyzer.srcname
- sourcename = u'%s:docstring of %s' % (filename, self.fullname)
+ return u'%s:docstring of %s' % (filename, self.fullname)
+ return u'docstring of %s' % self.fullname
+ def add_content(self, more_content, no_docstring=False):
+ """Add content from docstrings, attribute documentation and user."""
+ # set sourcename and add content from attribute documentation
+ sourcename = self.get_sourcename()
+ if self.analyzer:
attr_docs = self.analyzer.find_attr_docs()
if self.objpath:
key = ('.'.join(self.objpath[:-1]), self.objpath[-1])
@@ -534,8 +539,6 @@ class Documenter(object):
docstrings = [attr_docs[key]]
for i, line in enumerate(self.process_doc(docstrings)):
self.add_line(line, sourcename, i)
- else:
- sourcename = u'docstring of %s' % self.fullname
# add content from docstrings
if not no_docstring:
@@ -794,17 +797,19 @@ class Documenter(object):
if not self.check_module():
return
+ sourcename = self.get_sourcename()
+
# make sure that the result starts with an empty line. This is
# necessary for some situations where another directive preprocesses
# reST and no starting newline is present
- self.add_line(u'', '<autodoc>')
+ self.add_line(u'', sourcename)
# format the object's signature, if any
sig = self.format_signature()
# generate the directive header and options, if applicable
self.add_directive_header(sig)
- self.add_line(u'', '<autodoc>')
+ self.add_line(u'', sourcename)
# e.g. the module directive doesn't have content
self.indent += self.content_indent
@@ -854,15 +859,17 @@ class ModuleDocumenter(Documenter):
def add_directive_header(self, sig):
Documenter.add_directive_header(self, sig)
+ sourcename = self.get_sourcename()
+
# add some module-specific options
if self.options.synopsis:
self.add_line(
- u' :synopsis: ' + self.options.synopsis, '<autodoc>')
+ u' :synopsis: ' + self.options.synopsis, sourcename)
if self.options.platform:
self.add_line(
- u' :platform: ' + self.options.platform, '<autodoc>')
+ u' :platform: ' + self.options.platform, sourcename)
if self.options.deprecated:
- self.add_line(u' :deprecated:', '<autodoc>')
+ self.add_line(u' :deprecated:', sourcename)
def get_object_members(self, want_all):
if want_all:
@@ -1108,14 +1115,15 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter):
# add inheritance info, if wanted
if not self.doc_as_attr and self.options.show_inheritance:
- self.add_line(u'', '<autodoc>')
+ sourcename = self.get_sourcename()
+ self.add_line(u'', sourcename)
if hasattr(self.object, '__bases__') and len(self.object.__bases__):
bases = [b.__module__ in ('__builtin__', 'builtins') and
u':class:`%s`' % b.__name__ or
u':class:`%s.%s`' % (b.__module__, b.__name__)
for b in self.object.__bases__]
self.add_line(_(u' Bases: %s') % ', '.join(bases),
- '<autodoc>')
+ sourcename)
def get_doc(self, encoding=None, ignore=1):
lines = getattr(self, '_new_docstrings', None)
@@ -1200,18 +1208,19 @@ class DataDocumenter(ModuleLevelDocumenter):
def add_directive_header(self, sig):
ModuleLevelDocumenter.add_directive_header(self, sig)
+ sourcename = self.get_sourcename()
if not self.options.annotation:
try:
objrepr = safe_repr(self.object)
except ValueError:
pass
else:
- self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
+ self.add_line(u' :annotation: = ' + objrepr, sourcename)
elif self.options.annotation is SUPPRESS:
pass
else:
self.add_line(u' :annotation: %s' % self.options.annotation,
- '<autodoc>')
+ sourcename)
def document_members(self, all_members=False):
pass
@@ -1311,6 +1320,7 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
def add_directive_header(self, sig):
ClassLevelDocumenter.add_directive_header(self, sig)
+ sourcename = self.get_sourcename()
if not self.options.annotation:
if not self._datadescriptor:
try:
@@ -1318,12 +1328,12 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
except ValueError:
pass
else:
- self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
+ self.add_line(u' :annotation: = ' + objrepr, sourcename)
elif self.options.annotation is SUPPRESS:
pass
else:
self.add_line(u' :annotation: %s' % self.options.annotation,
- '<autodoc>')
+ sourcename)
def add_content(self, more_content, no_docstring=False):
if not self._datadescriptor: