summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
authorErik M. Bray <embray@stsci.edu>2015-04-09 19:09:24 -0400
committerErik M. Bray <embray@stsci.edu>2015-04-09 19:09:24 -0400
commitdef08a206fd885557381309604b7bbd776cdc03c (patch)
treef75c2bf997a7e8dc9be3df2c88aa6c1e9cc5bc22 /sphinx/ext/autodoc.py
parent80eb821ec81840b79ed517cb5f73aff7df0c79d0 (diff)
downloadsphinx-git-def08a206fd885557381309604b7bbd776cdc03c.tar.gz
Fix documentation of descriptor classes that have a custom metaclass
(i.e. a subclass of type). This avoids using string comparisons to do type checks, except in the case of the fix for #1155, since in Python 3 there really seems to be no way to export the instancemethod type, short of using ctypes.
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index ff6a30ecc..1fab725d7 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -34,6 +34,11 @@ from sphinx.util.inspect import getargspec, isdescriptor, safe_getmembers, \
from sphinx.util.docstrings import prepare_docstring
+# 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
@@ -1309,10 +1314,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))