Merge pull request #9797 from tk0miya/9757_inherited_classmethods

Fix #9757: autodoc_inherit_docstrings does not effect to overriden classmethods
This commit is contained in:
Takeshi KOMIYA 2021-10-31 00:33:38 +09:00 committed by GitHub
commit 2b5c55e45a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -64,6 +64,8 @@ Bugs fixed
* #9755: autodoc: memory addresses are shown for aliases
* #9752: autodoc: Failed to detect type annotation for slots attribute
* #9756: autodoc: Crashed if classmethod does not have __func__ attribute
* #9757: autodoc: :confval:`autodoc_inherit_docstrings` does not effect to
overriden classmethods
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
is not 'py'
* #9670: html: Fix download file with special characters

View File

@ -866,7 +866,9 @@ def getdoc(obj: Any, attrgetter: Callable = safe_getattr,
for basecls in getmro(cls):
meth = basecls.__dict__.get(name)
if meth and hasattr(meth, '__func__'):
return getdoc(meth.__func__)
doc = getdoc(meth.__func__)
if doc is not None or not allow_inherited:
return doc
doc = attrgetter(obj, '__doc__', None)
if ispartial(obj) and doc == obj.__class__.__doc__:

View File

@ -677,6 +677,25 @@ def test_unpartial():
assert inspect.unpartial(func3) is func1
def test_getdoc_inherited_classmethod():
class Foo:
@classmethod
def meth(self):
"""
docstring
indented text
"""
class Bar(Foo):
@classmethod
def meth(self):
# inherited classmethod
pass
assert inspect.getdoc(Bar.meth, getattr, False, Bar, "meth") is None
assert inspect.getdoc(Bar.meth, getattr, True, Bar, "meth") == Foo.meth.__doc__
def test_getdoc_inherited_decorated_method():
class Foo:
def meth(self):