Merge pull request #9079 from tk0miya/9078_async_staticmethod

Fix autodoc: Async staticmethods/ classmethods are considered as not async
This commit is contained in:
Takeshi KOMIYA 2021-04-11 02:10:16 +09:00 committed by GitHub
commit 43dc09175f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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)