diff options
Diffstat (limited to 'sphinx/util/inspect.py')
-rw-r--r-- | sphinx/util/inspect.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 17b19ae76..88f8dffd3 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -526,13 +526,14 @@ def signature_from_str(signature: str) -> inspect.Signature: def getdoc(obj: Any, attrgetter: Callable = safe_getattr, - allow_inherited: bool = False) -> str: + allow_inherited: bool = False, cls: Any = None, name: str = None) -> str: """Get the docstring for the object. This tries to obtain the docstring for some kind of objects additionally: * partial functions * inherited docstring + * inherited decorated methods """ doc = attrgetter(obj, '__doc__', None) if ispartial(obj) and doc == obj.__class__.__doc__: @@ -540,4 +541,14 @@ def getdoc(obj: Any, attrgetter: Callable = safe_getattr, elif doc is None and allow_inherited: doc = inspect.getdoc(obj) + if doc is None and cls: + # inspect.getdoc() does not support some kind of inherited and decorated methods. + # This tries to obtain the docstring from super classes. + for basecls in getattr(cls, '__mro__', []): + meth = safe_getattr(basecls, name, None) + if meth: + doc = inspect.getdoc(meth) + if doc: + break + return doc |