mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #3644 from jdemeyer/inspect_isfunction
Use inspect instead of checking types
This commit is contained in:
commit
4b2cacddf9
@ -16,7 +16,7 @@ import sys
|
|||||||
import inspect
|
import inspect
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
from types import FunctionType, BuiltinFunctionType, MethodType, ModuleType
|
from types import FunctionType, MethodType, ModuleType
|
||||||
|
|
||||||
from six import PY2, iterkeys, iteritems, itervalues, text_type, class_types, \
|
from six import PY2, iterkeys, iteritems, itervalues, text_type, class_types, \
|
||||||
string_types, StringIO
|
string_types, StringIO
|
||||||
@ -1341,7 +1341,7 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ
|
|||||||
@classmethod
|
@classmethod
|
||||||
def can_document_member(cls, member, membername, isattr, parent):
|
def can_document_member(cls, member, membername, isattr, parent):
|
||||||
# type: (Any, unicode, bool, Any) -> bool
|
# type: (Any, unicode, bool, Any) -> bool
|
||||||
return isinstance(member, (FunctionType, BuiltinFunctionType))
|
return inspect.isfunction(member) or inspect.isbuiltin(member)
|
||||||
|
|
||||||
def format_args(self):
|
def format_args(self):
|
||||||
# type: () -> unicode
|
# type: () -> unicode
|
||||||
@ -1637,13 +1637,16 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
|
|||||||
# some non-data descriptors as methods
|
# some non-data descriptors as methods
|
||||||
priority = 10
|
priority = 10
|
||||||
|
|
||||||
method_types = (FunctionType, BuiltinFunctionType, MethodType)
|
@staticmethod
|
||||||
|
def is_function_or_method(obj):
|
||||||
|
return inspect.isfunction(obj) or inspect.isbuiltin(obj) or inspect.ismethod(obj)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_document_member(cls, member, membername, isattr, parent):
|
def can_document_member(cls, member, membername, isattr, parent):
|
||||||
# type: (Any, unicode, bool, Any) -> bool
|
# type: (Any, unicode, bool, Any) -> bool
|
||||||
non_attr_types = cls.method_types + (type, MethodDescriptorType)
|
non_attr_types = (type, MethodDescriptorType)
|
||||||
isdatadesc = isdescriptor(member) and not \
|
isdatadesc = isdescriptor(member) and not \
|
||||||
|
cls.is_function_or_method(member) and not \
|
||||||
isinstance(member, non_attr_types) and not \
|
isinstance(member, non_attr_types) and not \
|
||||||
type(member).__name__ == "instancemethod"
|
type(member).__name__ == "instancemethod"
|
||||||
# That last condition addresses an obscure case of C-defined
|
# That last condition addresses an obscure case of C-defined
|
||||||
@ -1663,7 +1666,7 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
|
|||||||
if isenumattribute(self.object):
|
if isenumattribute(self.object):
|
||||||
self.object = self.object.value
|
self.object = self.object.value
|
||||||
if isdescriptor(self.object) and \
|
if isdescriptor(self.object) and \
|
||||||
not isinstance(self.object, self.method_types):
|
not self.is_function_or_method(self.object):
|
||||||
self._datadescriptor = True
|
self._datadescriptor = True
|
||||||
else:
|
else:
|
||||||
# if it's not a data descriptor
|
# if it's not a data descriptor
|
||||||
|
Loading…
Reference in New Issue
Block a user