diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-28 01:02:00 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-01 22:05:45 +0900 |
commit | 25fc47e6b7890aec22b2c24e68e7febfaee848e0 (patch) | |
tree | e13193b4088815bccb8c2166cdb5a8908d2e8e0d /sphinx/util/inspect.py | |
parent | 5460ad6925199b57b27b7d059825d3560872edbb (diff) | |
download | sphinx-git-25fc47e6b7890aec22b2c24e68e7febfaee848e0.tar.gz |
Fix #7559: autodoc: misdetects a sync function is async
Diffstat (limited to 'sphinx/util/inspect.py')
-rw-r--r-- | sphinx/util/inspect.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 38777728a..9eb05b29b 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -125,13 +125,15 @@ def unwrap(obj: Any) -> Any: return obj -def unwrap_all(obj: Any) -> Any: +def unwrap_all(obj: Any, *, stop: Callable = None) -> Any: """ Get an original object from wrapped object (unwrapping partials, wrapped functions, and other decorators). """ while True: - if ispartial(obj): + if stop and stop(obj): + return obj + elif ispartial(obj): obj = obj.func elif inspect.isroutine(obj) and hasattr(obj, '__wrapped__'): obj = obj.__wrapped__ @@ -287,7 +289,8 @@ def isroutine(obj: Any) -> bool: def iscoroutinefunction(obj: Any) -> bool: """Check if the object is coroutine-function.""" - obj = unwrap_all(obj) + # unwrap staticmethod, classmethod and partial (except wrappers) + obj = unwrap_all(obj, stop=lambda o: hasattr(o, '__wrapped__')) 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) |