Commits

Georg Brandl  committed 807775f

Fix "fixed" descriptor handling, and add tests.

  • Participants
  • Parent commits 3f7454a

Comments (0)

Files changed (3)

 Release 0.6.4 (in development)
 ==============================
 
+* Fix the handling of non-data descriptors in autodoc.
+
 
 Release 0.6.3 (Sep 03, 2009)
 ============================

File sphinx/ext/autodoc.py

     # some non-data descriptors as methods
     priority = 10
 
+    method_types = (FunctionType, BuiltinFunctionType, MethodType)
+
     @classmethod
     def can_document_member(cls, member, membername, isattr, parent):
-        return (isdescriptor(member) and not
-                isinstance(member, (FunctionType, BuiltinFunctionType))) \
-               or (not isinstance(parent, ModuleDocumenter) and isattr)
+        isdatadesc = isdescriptor(member) and not \
+                     isinstance(member, cls.method_types)
+        return isdatadesc or \
+               (isattr and not isinstance(parent, ModuleDocumenter))
 
     def document_members(self, all_members=False):
         pass

File tests/test_autodoc.py

     options.exclude_members = set(['excludemeth'])
     assert_processes(should, 'class', 'Class')
     should.extend([('attribute', 'test_autodoc.Class.prop'),
+                   ('attribute', 'test_autodoc.Class.descr'),
                    ('attribute', 'test_autodoc.Class.attr'),
                    ('attribute', 'test_autodoc.Class.docattr'),
                    ('attribute', 'test_autodoc.Class.udocattr')])
                       ('method', 'test_autodoc.Outer.Inner.meth')],
                      'class', 'Outer', all_members=True)
 
+    # test descriptor docstrings
+    assert_result_contains('   Descriptor instance docstring.',
+                           'attribute', 'test_autodoc.Class.descr')
+
     # test generation for C modules (which have no source file)
     directive.env.currmodule = 'time'
     assert_processes([('function', 'time.asctime')], 'function', 'asctime')
     def f(self):
         """Exception method."""
 
+class CustomDataDescriptor(object):
+    """Descriptor class docstring."""
+
+    def __init__(self, doc):
+        self.__doc__ = doc
+
+    def __get__(self, obj, type=None):
+        if obj is None:
+            return self
+        return 42
+
 class Base(object):
     def inheritedmeth(self):
         """Inherited function."""
 class Class(Base):
     """Class to document."""
 
+    descr = CustomDataDescriptor("Descriptor instance docstring.")
+
     def meth(self):
         """Function."""