diff options
Diffstat (limited to 'sphinx/util/inspect.py')
-rw-r--r-- | sphinx/util/inspect.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 3a39bde1d..24ea49ae0 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -871,6 +871,13 @@ def getdoc(obj: Any, attrgetter: Callable = safe_getattr, * inherited docstring * inherited decorated methods """ + def getdoc_internal(obj: Any, attrgetter: Callable = safe_getattr) -> Optional[str]: + doc = attrgetter(obj, '__doc__', None) + if isinstance(doc, str): + return doc + else: + return None + if cls and name and isclassmethod(obj, cls, name): for basecls in getmro(cls): meth = basecls.__dict__.get(name) @@ -879,7 +886,7 @@ def getdoc(obj: Any, attrgetter: Callable = safe_getattr, if doc is not None or not allow_inherited: return doc - doc = attrgetter(obj, '__doc__', None) + doc = getdoc_internal(obj) if ispartial(obj) and doc == obj.__class__.__doc__: return getdoc(obj.func) elif doc is None and allow_inherited: @@ -888,7 +895,7 @@ def getdoc(obj: Any, attrgetter: Callable = safe_getattr, for basecls in getmro(cls): meth = safe_getattr(basecls, name, None) if meth is not None: - doc = attrgetter(meth, '__doc__', None) + doc = getdoc_internal(meth) if doc is not None: break |