summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-04-11 02:10:16 +0900
committerGitHub <noreply@github.com>2021-04-11 02:10:16 +0900
commit43dc09175fb00b9bd9fa6ce31ea8082cfb85de91 (patch)
treeeae2f424f225f4d131d49741fddaeb78afafba3b
parent7b97c8cba2ad475e36d4663304d673502a89a92d (diff)
parent289d0783501e4e29574da5a2f7f109ce1d802034 (diff)
downloadsphinx-git-43dc09175fb00b9bd9fa6ce31ea8082cfb85de91.tar.gz
Merge pull request #9079 from tk0miya/9078_async_staticmethod
Fix autodoc: Async staticmethods/ classmethods are considered as not async
-rw-r--r--CHANGES2
-rw-r--r--sphinx/util/inspect.py14
2 files changed, 14 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index c4fae82a2..baf868e05 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,8 @@ Features added
Bugs fixed
----------
+* #9078: autodoc: Async staticmethods and classmethods are considered as non
+ async coroutine-functions with Python3.10
* #8870: The style of toctree captions has been changed with docutils-0.17
* #9001: The style of ``sidebar`` directive has been changed with docutils-0.17
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 5477e64f7..9fcd3df75 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -352,8 +352,18 @@ def isroutine(obj: Any) -> bool:
def iscoroutinefunction(obj: Any) -> bool:
"""Check if the object is coroutine-function."""
- # unwrap staticmethod, classmethod and partial (except wrappers)
- obj = unwrap_all(obj, stop=lambda o: hasattr(o, '__wrapped__'))
+ def iswrappedcoroutine(obj: Any) -> bool:
+ """Check if the object is wrapped coroutine-function."""
+ if isstaticmethod(obj) or isclassmethod(obj) or ispartial(obj):
+ # staticmethod, classmethod and partial method are not a wrapped coroutine-function
+ # Note: Since 3.10, staticmethod and classmethod becomes a kind of wrappers
+ return False
+ elif hasattr(obj, '__wrapped__'):
+ return True
+ else:
+ return False
+
+ obj = unwrap_all(obj, stop=iswrappedcoroutine)
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)