mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#568: Fix lookup of class attribute documentation on descriptors so that comment documentation now works.
Needed to port assignment of ``self.parent`` from trunk.
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,6 +1,9 @@
|
||||
Release 1.0.7 (in development)
|
||||
==============================
|
||||
|
||||
* #568: Fix lookup of class attribute documentation on descriptors
|
||||
so that comment documentation now works.
|
||||
|
||||
* Fix traceback with ``only`` directives preceded by targets.
|
||||
|
||||
* Fix tracebacks occurring for duplicate C++ domain objects.
|
||||
|
||||
@@ -256,6 +256,9 @@ class Documenter(object):
|
||||
self.retann = None
|
||||
# the object to document (set after import_object succeeds)
|
||||
self.object = None
|
||||
self.object_name = None
|
||||
# the parent/owner of the object to document
|
||||
self.parent = None
|
||||
# the module analyzer to get at attribute docs, or None
|
||||
self.analyzer = None
|
||||
|
||||
@@ -321,9 +324,13 @@ class Documenter(object):
|
||||
"""
|
||||
try:
|
||||
__import__(self.modname)
|
||||
parent = None
|
||||
obj = self.module = sys.modules[self.modname]
|
||||
for part in self.objpath:
|
||||
parent = obj
|
||||
obj = self.get_attr(obj, part)
|
||||
self.object_name = part
|
||||
self.parent = parent
|
||||
self.object = obj
|
||||
return True
|
||||
# this used to only catch SyntaxError, ImportError and AttributeError,
|
||||
@@ -1065,6 +1072,10 @@ class AttributeDocumenter(ClassLevelDocumenter):
|
||||
def document_members(self, all_members=False):
|
||||
pass
|
||||
|
||||
def get_real_modname(self):
|
||||
return self.get_attr(self.parent or self.object, '__module__', None) \
|
||||
or self.modname
|
||||
|
||||
|
||||
class InstanceAttributeDocumenter(AttributeDocumenter):
|
||||
"""
|
||||
|
||||
@@ -17,6 +17,7 @@ from docutils.statemachine import ViewList
|
||||
from sphinx.ext.autodoc import AutoDirective, add_documenter, \
|
||||
ModuleLevelDocumenter, FunctionDocumenter, cut_lines, between, ALL
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
def setup_module():
|
||||
global app, lid, options, directive
|
||||
@@ -416,6 +417,7 @@ def test_generate():
|
||||
('attribute', 'test_autodoc.Class.attr'),
|
||||
('attribute', 'test_autodoc.Class.docattr'),
|
||||
('attribute', 'test_autodoc.Class.udocattr'),
|
||||
('attribute', 'test_autodoc.Class.mdocattr'),
|
||||
('attribute', 'test_autodoc.Class.inst_attr_comment'),
|
||||
('attribute', 'test_autodoc.Class.inst_attr_string')
|
||||
])
|
||||
@@ -484,11 +486,19 @@ def test_generate():
|
||||
' .. py:attribute:: Class.prop',
|
||||
' .. py:attribute:: Class.docattr',
|
||||
' .. py:attribute:: Class.udocattr',
|
||||
' .. py:attribute:: Class.mdocattr',
|
||||
' .. py:attribute:: Class.inst_attr_comment',
|
||||
' .. py:attribute:: Class.inst_attr_string',
|
||||
' .. py:method:: Class.inheritedmeth()',
|
||||
],
|
||||
'class', 'Class', member_order='bysource', all_members=True)
|
||||
del directive.env.temp_data['py:module']
|
||||
|
||||
# test attribute initialized to class instance from other module
|
||||
directive.env.temp_data['autodoc:class'] = 'test_autodoc.Class'
|
||||
assert_result_contains(u' should be documented as well - s\xfc\xdf',
|
||||
'attribute', 'mdocattr')
|
||||
del directive.env.temp_data['autodoc:class']
|
||||
|
||||
|
||||
# --- generate fodder ------------
|
||||
@@ -552,6 +562,10 @@ class Class(Base):
|
||||
udocattr = 'quux'
|
||||
u"""should be documented as well - süß"""
|
||||
|
||||
# initialized to any class imported from another module
|
||||
mdocattr = StringIO()
|
||||
"""should be documented as well - süß"""
|
||||
|
||||
def __init__(self, arg):
|
||||
#: a documented instance attribute
|
||||
self.inst_attr_comment = None
|
||||
|
||||
Reference in New Issue
Block a user