mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merged in JonnyJD/sphinx/autodoc_novalue (pull request #109)
feature: autodoc: add :annotation: option for autodata and autoattribute
This commit is contained in:
commit
e732807869
@ -197,8 +197,23 @@ inserting them into the page source under a suitable :rst:dir:`py:module`,
|
|||||||
automethod
|
automethod
|
||||||
autoattribute
|
autoattribute
|
||||||
|
|
||||||
These work exactly like :rst:dir:`autoclass` etc., but do not offer the
|
These work exactly like :rst:dir:`autoclass` etc.,
|
||||||
options used for automatic member documentation.
|
but do not offer the options used for automatic member documentation.
|
||||||
|
|
||||||
|
:rst:dir:`autodata` and :rst:dir:`autoattribute` support
|
||||||
|
the ``annotation`` option.
|
||||||
|
Without this option, the representation of the object
|
||||||
|
will be shown in the documentation.
|
||||||
|
When the option is given without arguments,
|
||||||
|
only the name of the object will be printed::
|
||||||
|
|
||||||
|
.. autodata:: CD_DRIVE
|
||||||
|
:annotation:
|
||||||
|
|
||||||
|
You can tell sphinx what should be printed after the name::
|
||||||
|
|
||||||
|
.. autodata:: CD_DRIVE
|
||||||
|
:annotation: = your CD device name
|
||||||
|
|
||||||
For module data members and class attributes, documentation can either be put
|
For module data members and class attributes, documentation can either be put
|
||||||
into a comment with special formatting (using a ``#:`` to start the comment
|
into a comment with special formatting (using a ``#:`` to start the comment
|
||||||
@ -234,6 +249,10 @@ inserting them into the page source under a suitable :rst:dir:`py:module`,
|
|||||||
.. versionchanged:: 1.1
|
.. versionchanged:: 1.1
|
||||||
Comment docs are now allowed on the same line after an assignment.
|
Comment docs are now allowed on the same line after an assignment.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.2
|
||||||
|
:rst:dir:`autodata` and :rst:dir:`autoattribute` have
|
||||||
|
an ``annotation`` option
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
If you document decorated functions or methods, keep in mind that autodoc
|
If you document decorated functions or methods, keep in mind that autodoc
|
||||||
|
@ -85,6 +85,15 @@ def members_set_option(arg):
|
|||||||
return ALL
|
return ALL
|
||||||
return set(x.strip() for x in arg.split(','))
|
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):
|
def bool_option(arg):
|
||||||
"""Used to convert flag options to auto directives. (Instead of
|
"""Used to convert flag options to auto directives. (Instead of
|
||||||
directives.flag(), which returns None).
|
directives.flag(), which returns None).
|
||||||
@ -1110,6 +1119,8 @@ class DataDocumenter(ModuleLevelDocumenter):
|
|||||||
objtype = 'data'
|
objtype = 'data'
|
||||||
member_order = 40
|
member_order = 40
|
||||||
priority = -10
|
priority = -10
|
||||||
|
option_spec = dict(ModuleLevelDocumenter.option_spec)
|
||||||
|
option_spec["annotation"] = annotation_option
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_document_member(cls, member, membername, isattr, parent):
|
def can_document_member(cls, member, membername, isattr, parent):
|
||||||
@ -1117,12 +1128,18 @@ class DataDocumenter(ModuleLevelDocumenter):
|
|||||||
|
|
||||||
def add_directive_header(self, sig):
|
def add_directive_header(self, sig):
|
||||||
ModuleLevelDocumenter.add_directive_header(self, sig)
|
ModuleLevelDocumenter.add_directive_header(self, sig)
|
||||||
try:
|
if not self.options.annotation:
|
||||||
objrepr = safe_repr(self.object)
|
try:
|
||||||
except ValueError:
|
objrepr = safe_repr(self.object)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
|
||||||
|
elif self.options.annotation is SUPPRESS:
|
||||||
pass
|
pass
|
||||||
else:
|
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):
|
def document_members(self, all_members=False):
|
||||||
pass
|
pass
|
||||||
@ -1194,6 +1211,8 @@ class AttributeDocumenter(ClassLevelDocumenter):
|
|||||||
"""
|
"""
|
||||||
objtype = 'attribute'
|
objtype = 'attribute'
|
||||||
member_order = 60
|
member_order = 60
|
||||||
|
option_spec = dict(ModuleLevelDocumenter.option_spec)
|
||||||
|
option_spec["annotation"] = annotation_option
|
||||||
|
|
||||||
# must be higher than the MethodDocumenter, else it will recognize
|
# must be higher than the MethodDocumenter, else it will recognize
|
||||||
# some non-data descriptors as methods
|
# some non-data descriptors as methods
|
||||||
@ -1229,13 +1248,18 @@ class AttributeDocumenter(ClassLevelDocumenter):
|
|||||||
|
|
||||||
def add_directive_header(self, sig):
|
def add_directive_header(self, sig):
|
||||||
ClassLevelDocumenter.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:
|
try:
|
||||||
objrepr = safe_repr(self.object)
|
objrepr = safe_repr(self.object)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.add_line(u' :annotation: = ' + objrepr, '<autodoc>')
|
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):
|
def add_content(self, more_content, no_docstring=False):
|
||||||
if not self._datadescriptor:
|
if not self._datadescriptor:
|
||||||
|
@ -51,6 +51,7 @@ def setup_test():
|
|||||||
special_members = False,
|
special_members = False,
|
||||||
show_inheritance = False,
|
show_inheritance = False,
|
||||||
noindex = False,
|
noindex = False,
|
||||||
|
annotation = None,
|
||||||
synopsis = '',
|
synopsis = '',
|
||||||
platform = '',
|
platform = '',
|
||||||
deprecated = False,
|
deprecated = False,
|
||||||
|
Loading…
Reference in New Issue
Block a user