>>> from trio.lowlevel import enable_ki_protection
>>> async def foo():
... return
...
>>> @enable_ki_protection
... async def bar():
... return
...
>>> import inspect
>>> inspect.iscoroutinefunction(foo)
True
>>> inspect.iscoroutinefunction(bar)
False
Found when I tried to update coroutine_or_error in trio/_util.py to use inspect.iscoroutinefunction in #2668
|
# We can't check iscoroutinefunction(async_fn), because that will fail |
|
# for things like functools.partial objects wrapping an async |
|
# function. So we have to just call it and then check whether the |
|
# return value is a coroutine object. |
|
# Note: will not be necessary on python>=3.8, see https://bugs.python.org/issue34890 |
There are also a ton of wrapper/helper methods in tests that un-coroutinefunction-ify functions, which'd need to be modified in order to actually use iscoroutinefunction in couroutine_or_error. This means it'd probably also break a bunch of downstream code if coroutine_or_error was rewritten, but the upside of not having to call the function might mean that it's worth it (after a deprecation period)? That's probably for another issue though.
Found when I tried to update
coroutine_or_errorintrio/_util.pyto useinspect.iscoroutinefunctionin #2668trio/trio/_util.py
Lines 137 to 141 in 3146638
There are also a ton of wrapper/helper methods in tests that un-coroutinefunction-ify functions, which'd need to be modified in order to actually use
iscoroutinefunctionincouroutine_or_error. This means it'd probably also break a bunch of downstream code ifcoroutine_or_errorwas rewritten, but the upside of not having to call the function might mean that it's worth it (after a deprecation period)? That's probably for another issue though.