summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-09-16 04:25:53 +0200
committerGeorg Brandl <georg@python.org>2013-09-16 04:25:53 +0200
commite73280786960fb6703bc482e2285155657deb290 (patch)
treeade22afeff50784a74e2659523316c0a18b8968f /sphinx/ext/autodoc.py
parent5f4ace9aced2532d1f8275cfa94d3e41038de898 (diff)
parent649ab8030c8cab249cd0be28616a0f87b97571dd (diff)
downloadsphinx-git-e73280786960fb6703bc482e2285155657deb290.tar.gz
Merged in JonnyJD/sphinx/autodoc_novalue (pull request #109)
feature: autodoc: add :annotation: option for autodata and autoattribute
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 555a31066..3684c0c87 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -85,6 +85,15 @@ def members_set_option(arg):
return ALL
return set(x.strip() for x in arg.split(','))
+SUPPRESS = object()
+
+def annotation_option(arg):
+ if arg is None:
+ # suppress showing the representation of the object
+ return SUPPRESS
+ else:
+ return arg
+
def bool_option(arg):
"""Used to convert flag options to auto directives. (Instead of
directives.flag(), which returns None).
@@ -1110,6 +1119,8 @@ class DataDocumenter(ModuleLevelDocumenter):
objtype = 'data'
member_order = 40
priority = -10
+ option_spec = dict(ModuleLevelDocumenter.option_spec)
+ option_spec["annotation"] = annotation_option
@classmethod
def can_document_member(cls, member, membername, isattr, parent):
@@ -1117,12 +1128,18 @@ class DataDocumenter(ModuleLevelDocumenter):
def add_directive_header(self, sig):
ModuleLevelDocumenter.add_directive_header(self, sig)
- try:
- objrepr = safe_repr(self.object)
- except ValueError:
+ if not self.options.annotation:
+ try:
+ objrepr = safe_repr(self.object)
+ except ValueError:
+ pass
+ else:
+ self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
+ elif self.options.annotation is SUPPRESS:
pass
else:
- self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
+ self.add_line(u' :annotation: %s' % self.options.annotation,
+ '<autodoc>')
def document_members(self, all_members=False):
pass
@@ -1194,6 +1211,8 @@ class AttributeDocumenter(ClassLevelDocumenter):
"""
objtype = 'attribute'
member_order = 60
+ option_spec = dict(ModuleLevelDocumenter.option_spec)
+ option_spec["annotation"] = annotation_option
# must be higher than the MethodDocumenter, else it will recognize
# some non-data descriptors as methods
@@ -1229,13 +1248,18 @@ class AttributeDocumenter(ClassLevelDocumenter):
def add_directive_header(self, sig):
ClassLevelDocumenter.add_directive_header(self, sig)
- if not self._datadescriptor:
+ if not self._datadescriptor and not self.options.annotation:
try:
objrepr = safe_repr(self.object)
except ValueError:
pass
else:
self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
+ elif self.options.annotation is SUPPRESS:
+ pass
+ else:
+ self.add_line(u' :annotation: %s' % self.options.annotation,
+ '<autodoc>')
def add_content(self, more_content, no_docstring=False):
if not self._datadescriptor: