Skip to content

Commit

Permalink
Merge pull request #9797 from tk0miya/9757_inherited_classmethods
Browse files Browse the repository at this point in the history
Fix #9757: autodoc_inherit_docstrings does not effect to overriden classmethods
  • Loading branch information
tk0miya committed Oct 30, 2021
2 parents 4c91c03 + 3c5b31b commit 2b5c55e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion sphinx/util/inspect.py
Expand Up @@ -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__:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_util_inspect.py
Expand Up @@ -677,6 +677,25 @@ def func1(a, b, c):
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):
Expand Down

0 comments on commit 2b5c55e

Please sign in to comment.