mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #4415: autodoc classifies inherited classmethods as regular methods
This commit is contained in:
parent
a9f949e858
commit
cbb10d61f7
2
CHANGES
2
CHANGES
@ -16,6 +16,8 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #4415: autodoc classifies inherited classmethods as regular methods
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ from sphinx.application import ExtensionError
|
|||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.inspect import Signature, isdescriptor, safe_getmembers, \
|
from sphinx.util.inspect import Signature, isdescriptor, safe_getmembers, \
|
||||||
safe_getattr, object_description, is_builtin_class_method, \
|
safe_getattr, object_description, is_builtin_class_method, \
|
||||||
isenumattribute, getdoc
|
isenumattribute, isclassmethod, getdoc
|
||||||
from sphinx.util.docstrings import prepare_docstring
|
from sphinx.util.docstrings import prepare_docstring
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
@ -1261,8 +1261,10 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type:
|
|||||||
|
|
||||||
# to distinguish classmethod/staticmethod
|
# to distinguish classmethod/staticmethod
|
||||||
obj = self.parent.__dict__.get(self.object_name)
|
obj = self.parent.__dict__.get(self.object_name)
|
||||||
|
if obj is None:
|
||||||
|
obj = self.object
|
||||||
|
|
||||||
if isinstance(obj, classmethod):
|
if isclassmethod(obj):
|
||||||
self.directivetype = 'classmethod'
|
self.directivetype = 'classmethod'
|
||||||
# document class and static members before ordinary ones
|
# document class and static members before ordinary ones
|
||||||
self.member_order = self.member_order - 1
|
self.member_order = self.member_order - 1
|
||||||
|
@ -154,6 +154,20 @@ def isenumattribute(x):
|
|||||||
return isinstance(x, enum.Enum)
|
return isinstance(x, enum.Enum)
|
||||||
|
|
||||||
|
|
||||||
|
def isclassmethod(obj):
|
||||||
|
# type: (Any) -> bool
|
||||||
|
"""Check if the object is classmethod."""
|
||||||
|
if isinstance(obj, classmethod):
|
||||||
|
return True
|
||||||
|
elif inspect.ismethod(obj):
|
||||||
|
if getattr(obj, 'im_self', None): # py2
|
||||||
|
return True
|
||||||
|
elif getattr(obj, '__self__', None): # py3
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def isdescriptor(x):
|
def isdescriptor(x):
|
||||||
# type: (Any) -> bool
|
# type: (Any) -> bool
|
||||||
"""Check if the object is some kind of descriptor."""
|
"""Check if the object is some kind of descriptor."""
|
||||||
|
@ -64,6 +64,10 @@ class Base(object):
|
|||||||
def inheritedmeth(self):
|
def inheritedmeth(self):
|
||||||
"""Inherited function."""
|
"""Inherited function."""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def inheritedclassmeth(cls):
|
||||||
|
"""Inherited class method."""
|
||||||
|
|
||||||
|
|
||||||
class Derived(Base):
|
class Derived(Base):
|
||||||
def inheritedmeth(self):
|
def inheritedmeth(self):
|
||||||
|
@ -715,6 +715,7 @@ def test_generate():
|
|||||||
assert_processes(should, 'class', 'Class')
|
assert_processes(should, 'class', 'Class')
|
||||||
options.inherited_members = True
|
options.inherited_members = True
|
||||||
should.append(('method', 'target.Class.inheritedmeth'))
|
should.append(('method', 'target.Class.inheritedmeth'))
|
||||||
|
should.append(('method', 'target.Class.inheritedclassmeth'))
|
||||||
assert_processes(should, 'class', 'Class')
|
assert_processes(should, 'class', 'Class')
|
||||||
|
|
||||||
# test special members
|
# test special members
|
||||||
@ -798,6 +799,7 @@ def test_generate():
|
|||||||
' .. py:attribute:: Class.inst_attr_comment',
|
' .. py:attribute:: Class.inst_attr_comment',
|
||||||
' .. py:attribute:: Class.inst_attr_string',
|
' .. py:attribute:: Class.inst_attr_string',
|
||||||
' .. py:attribute:: Class._private_inst_attr',
|
' .. py:attribute:: Class._private_inst_attr',
|
||||||
|
' .. py:classmethod:: Class.inheritedclassmeth()',
|
||||||
' .. py:method:: Class.inheritedmeth()',
|
' .. py:method:: Class.inheritedmeth()',
|
||||||
],
|
],
|
||||||
'class', 'Class', member_order='bysource', all_members=True)
|
'class', 'Class', member_order='bysource', all_members=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user