diff --git a/CHANGES b/CHANGES index fec1b2bb8..672d44703 100644 --- a/CHANGES +++ b/CHANGES @@ -38,6 +38,8 @@ Release 1.0 (in development) Release 0.6.4 (in development) ============================== +* Fix the handling of non-data descriptors in autodoc. + Release 0.6.3 (Sep 03, 2009) ============================ diff --git a/EXAMPLES b/EXAMPLES index b6a03dea7..74a5961e4 100644 --- a/EXAMPLES +++ b/EXAMPLES @@ -35,6 +35,7 @@ included, please mail to `the Google group * MyHDL: http://www.myhdl.org/doc/0.6/ * NetworkX: http://networkx.lanl.gov/ * NOC: http://trac.nocproject.org/trac/wiki/NocGuide +* nose: http://somethingaboutorange.com/mrl/projects/nose/ * NumPy: http://docs.scipy.org/doc/numpy/reference/ * ObjectListView: http://objectlistview.sourceforge.net/python * Open ERP: http://doc.openerp.com/ diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 705853c20..ef09b61a1 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -971,10 +971,10 @@ class MethodDocumenter(ClassLevelDocumenter): """ objtype = 'method' member_order = 50 + priority = 0 @classmethod def can_document_member(cls, member, membername, isattr, parent): - # other attributes are recognized via the module analyzer return inspect.isroutine(member) and \ not isinstance(parent, ModuleDocumenter) @@ -1017,11 +1017,18 @@ class AttributeDocumenter(ClassLevelDocumenter): objtype = 'attribute' member_order = 60 + # must be higher than the MethodDocumenter, else it will recognize + # 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 diff --git a/sphinx/themes/basic/static/basic.css b/sphinx/themes/basic/static/basic.css index b52e5f8bd..a440964e7 100644 --- a/sphinx/themes/basic/static/basic.css +++ b/sphinx/themes/basic/static/basic.css @@ -392,7 +392,7 @@ span.eqno { div.document, div.documentwrapper, div.bodywrapper { - margin: 0; + margin: 0 !important; width: 100%; } diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 8e0114386..687fbd0d7 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -379,6 +379,7 @@ def test_generate(): 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')]) @@ -427,6 +428,10 @@ def test_generate(): ('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') @@ -445,6 +450,17 @@ class CustomEx(Exception): 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.""" @@ -452,6 +468,8 @@ class Base(object): class Class(Base): """Class to document.""" + descr = CustomDataDescriptor("Descriptor instance docstring.") + def meth(self): """Function."""