From 65e2fdc191f656c35e6add0f33427a7b63cbcafe Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 18 Aug 2019 23:59:06 +0900 Subject: [PATCH] Fix #6605: autodoc: crashed when target code contains custom method-like objects --- CHANGES | 1 + sphinx/util/inspect.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index f42ef0ad1d..ea50011a20 100644 --- a/CHANGES +++ b/CHANGES @@ -56,6 +56,7 @@ Bugs fixed imports when ``'bysource'`` order * #6574: autodoc: missing type annotation for variadic and keyword parameters * #6589: autodoc: Formatting issues with autodoc_typehints='none' +* #6605: autodoc: crashed when target code contains custom method-like objects * #6498: autosummary: crashed with wrong autosummary_generate setting * #6507: autosummary: crashes without no autosummary_generate setting * #6511: LaTeX: autonumbered list can not be customized in LaTeX diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 37ad34153c..2a6c0018e0 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -207,9 +207,12 @@ def isbuiltin(obj: Any) -> bool: def iscoroutinefunction(obj: Any) -> bool: """Check if the object is coroutine-function.""" - if inspect.iscoroutinefunction(obj): + if hasattr(obj, '__code__') and inspect.iscoroutinefunction(obj): + # check obj.__code__ because iscoroutinefunction() crashes for custom method-like + # objects (see https://github.com/sphinx-doc/sphinx/issues/6605) return True - elif ispartial(obj) and inspect.iscoroutinefunction(obj.func): + elif (ispartial(obj) and hasattr(obj.func, '__code__') and + inspect.iscoroutinefunction(obj.func)): # partialed return True else: