Skip to content

Commit 43dc091

Browse files
authored
Merge pull request #9079 from tk0miya/9078_async_staticmethod
Fix autodoc: Async staticmethods/ classmethods are considered as not async
2 parents 7b97c8c + 289d078 commit 43dc091

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Features added
1818
Bugs fixed
1919
----------
2020

21+
* #9078: autodoc: Async staticmethods and classmethods are considered as non
22+
async coroutine-functions with Python3.10
2123
* #8870: The style of toctree captions has been changed with docutils-0.17
2224
* #9001: The style of ``sidebar`` directive has been changed with docutils-0.17
2325

sphinx/util/inspect.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,18 @@ def isroutine(obj: Any) -> bool:
352352

353353
def iscoroutinefunction(obj: Any) -> bool:
354354
"""Check if the object is coroutine-function."""
355-
# unwrap staticmethod, classmethod and partial (except wrappers)
356-
obj = unwrap_all(obj, stop=lambda o: hasattr(o, '__wrapped__'))
355+
def iswrappedcoroutine(obj: Any) -> bool:
356+
"""Check if the object is wrapped coroutine-function."""
357+
if isstaticmethod(obj) or isclassmethod(obj) or ispartial(obj):
358+
# staticmethod, classmethod and partial method are not a wrapped coroutine-function
359+
# Note: Since 3.10, staticmethod and classmethod becomes a kind of wrappers
360+
return False
361+
elif hasattr(obj, '__wrapped__'):
362+
return True
363+
else:
364+
return False
365+
366+
obj = unwrap_all(obj, stop=iswrappedcoroutine)
357367
if hasattr(obj, '__code__') and inspect.iscoroutinefunction(obj):
358368
# check obj.__code__ because iscoroutinefunction() crashes for custom method-like
359369
# objects (see https://github.com/sphinx-doc/sphinx/issues/6605)

0 commit comments

Comments
 (0)