mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-12 08:25:01 -05:00
autodoc: novalue option for autodata and autoattribute
This adds a ":novalue:" option to "autodata" and "autoattribute" from the autodoc extension. When the option is set, no value will be in the output.
This commit is contained in:
1 parent
de1f19da36
commit
6b9f35455d
1 file changed
+12
-7
+12
-7
@@ -1097,6 +1097,8 @@ class DataDocumenter(ModuleLevelDocumenter):
|
||||
objtype = 'data'
|
||||
member_order = 40
|
||||
priority = -10
|
||||
option_spec = ModuleLevelDocumenter.option_spec
|
||||
option_spec["novalue"] = bool_option
|
||||
|
||||
@classmethod
|
||||
def can_document_member(cls, member, membername, isattr, parent):
|
||||
@@ -1104,12 +1106,13 @@ class DataDocumenter(ModuleLevelDocumenter):
|
||||
|
||||
def add_directive_header(self, sig):
|
||||
ModuleLevelDocumenter.add_directive_header(self, sig)
|
||||
try:
|
||||
objrepr = safe_repr(self.object)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
|
||||
if not "novalue" in self.options:
|
||||
try:
|
||||
objrepr = safe_repr(self.object)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
|
||||
|
||||
def document_members(self, all_members=False):
|
||||
pass
|
||||
@@ -1181,6 +1184,8 @@ class AttributeDocumenter(ClassLevelDocumenter):
|
||||
"""
|
||||
objtype = 'attribute'
|
||||
member_order = 60
|
||||
option_spec = ModuleLevelDocumenter.option_spec
|
||||
option_spec["novalue"] = bool_option
|
||||
|
||||
# must be higher than the MethodDocumenter, else it will recognize
|
||||
# some non-data descriptors as methods
|
||||
@@ -1216,7 +1221,7 @@ class AttributeDocumenter(ClassLevelDocumenter):
|
||||
|
||||
def add_directive_header(self, sig):
|
||||
ClassLevelDocumenter.add_directive_header(self, sig)
|
||||
if not self._datadescriptor:
|
||||
if not self._datadescriptor or "novalue" in self.options:
|
||||
try:
|
||||
objrepr = safe_repr(self.object)
|
||||
except ValueError:
|
||||
|
||||
Reference in new issue
Block a user