diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-11-21 19:48:47 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-11-21 19:50:53 +0300 |
commit | 80f84260bad23b0f71b86636a987a2b9dd49b828 (patch) | |
tree | 307ff5557d7081307d5ec086fcd743563fcd12ad /sphinx/util | |
parent | e5424b38e981b7b61184583a7ebc8c124d1e9a1e (diff) |
Fix #9879: autodoc: AttributeError for object having invalid __doc__
Diffstat (limited to 'sphinx/util')
-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 |