Skip to content

@enable_ki_protection breaks inspect.iscoroutinefunction #2670

Closed
@jakkdl

Description

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

trio/trio/_util.py

Lines 137 to 141 in 3146638

# 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions