Fix "fixed" descriptor handling, and add tests.

This commit is contained in:
Georg Brandl 2009-10-25 11:26:10 +01:00
parent 9088649e0f
commit f04ca65690
3 changed files with 26 additions and 3 deletions

View File

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

View File

@ -1015,11 +1015,14 @@ class AttributeDocumenter(ClassLevelDocumenter):
# 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

View File

@ -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."""