Georg Brandl avatar Georg Brandl committed c0c3d0e

#568: Fix lookup of class attribute documentation on descriptors so that comment documentation now works.

Needed to port assignment of ``self.parent`` from trunk.

Comments (0)

Files changed (3)

 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.


         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
+            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,
     def document_members(self, all_members=False):
+    def get_real_modname(self):
+        return self.get_attr(self.parent or self.object, '__module__', None) \
+               or self.modname
 class InstanceAttributeDocumenter(AttributeDocumenter):


 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
                    ('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')
                   '   .. 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 ------------
     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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.