Skip to content

Commit

Permalink
Merge branch 'fix-attr-documenter' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
shimizukawa committed Nov 24, 2016
2 parents 76f2ed9 + def08a2 commit 3284e89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 11 additions & 3 deletions sphinx/ext/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
except ImportError:
typing = None

# This type isn't exposed directly in any modules, but can be found
# here in most Python versions
MethodDescriptorType = type(type.__subclasses__)


#: extended signature RE: with explicit module name separated by ::
py_ext_sig_re = re.compile(
r'''^ ([\w.]+::)? # explicit module name
Expand Down Expand Up @@ -1466,10 +1471,13 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):

@classmethod
def can_document_member(cls, member, membername, isattr, parent):
non_attr_types = cls.method_types + (type, MethodDescriptorType)
isdatadesc = isdescriptor(member) and not \
isinstance(member, cls.method_types) and not \
type(member).__name__ in ("type", "method_descriptor",
"instancemethod")
isinstance(member, non_attr_types) and not \
type(member).__name__ == "instancemethod"
# That last condition addresses an obscure case of C-defined
# methods using a deprecated type in Python 3, that is not otherwise
# exported anywhere by Python
return isdatadesc or (not isinstance(parent, ModuleDocumenter) and
not inspect.isroutine(member) and
not isinstance(member, class_types))
Expand Down
14 changes: 12 additions & 2 deletions tests/test_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from util import TestApp, Struct, raises, SkipTest # NOQA
from nose.tools import with_setup, eq_

from six import StringIO
from six import StringIO, add_metaclass
from docutils.statemachine import ViewList

from sphinx.ext.autodoc import AutoDirective, add_documenter, \
Expand Down Expand Up @@ -826,11 +826,13 @@ def assert_order(items, objtype, name, member_order, **kw):
del directive.env.ref_context['py:module']

# test descriptor class documentation
options.members = ['CustomDataDescriptor']
options.members = ['CustomDataDescriptor', 'CustomDataDescriptor2']
assert_result_contains('.. py:class:: CustomDataDescriptor(doc)',
'module', 'test_autodoc')
assert_result_contains(' .. py:method:: CustomDataDescriptor.meth()',
'module', 'test_autodoc')
assert_result_contains('.. py:class:: CustomDataDescriptor2(doc)',
'module', 'test_autodoc')

# --- generate fodder ------------
__all__ = ['Class']
Expand Down Expand Up @@ -862,6 +864,14 @@ def meth(self):
return "The Answer"


class CustomDataDescriptorMeta(type):
"""Descriptor metaclass docstring."""

@add_metaclass(CustomDataDescriptorMeta)
class CustomDataDescriptor2(CustomDataDescriptor):
"""Descriptor class with custom metaclass docstring."""


def _funky_classmethod(name, b, c, d, docstring=None):
"""Generates a classmethod for a class from a template by filling out
some arguments."""
Expand Down

0 comments on commit 3284e89

Please sign in to comment.