diff --git a/asgiref/compatibility.py b/asgiref/compatibility.py index eccaee0d..3a2a63e6 100644 --- a/asgiref/compatibility.py +++ b/asgiref/compatibility.py @@ -1,6 +1,7 @@ -import asyncio import inspect +from .sync import iscoroutinefunction + def is_double_callable(application): """ @@ -18,10 +19,10 @@ def is_double_callable(application): if hasattr(application, "__call__"): # We only check to see if its __call__ is a coroutine function - # if it's not, it still might be a coroutine function itself. - if asyncio.iscoroutinefunction(application.__call__): + if iscoroutinefunction(application.__call__): return False # Non-classes we just check directly - return not asyncio.iscoroutinefunction(application) + return not iscoroutinefunction(application) def double_to_single_callable(application): diff --git a/asgiref/sync.py b/asgiref/sync.py index e0c10704..9b5a959f 100644 --- a/asgiref/sync.py +++ b/asgiref/sync.py @@ -378,7 +378,7 @@ def __init__( self.func = func functools.update_wrapper(self, func) self._thread_sensitive = thread_sensitive - self._is_coroutine = asyncio.coroutines._is_coroutine # type: ignore + markcoroutinefunction(self) if thread_sensitive and executor is not None: raise TypeError("executor must not be set when thread_sensitive is True") self._executor = executor diff --git a/tests/test_sync.py b/tests/test_sync.py index 022a1743..15640e65 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -10,7 +10,7 @@ import pytest -from asgiref.sync import ThreadSensitiveContext, async_to_sync, sync_to_async +from asgiref.sync import ThreadSensitiveContext, async_to_sync, sync_to_async, iscoroutinefunction from asgiref.timeout import timeout @@ -645,8 +645,8 @@ def test_sync_to_async_detected_as_coroutinefunction(): def sync_func(): return - assert not asyncio.iscoroutinefunction(sync_to_async) - assert asyncio.iscoroutinefunction(sync_to_async(sync_func)) + assert not iscoroutinefunction(sync_to_async) + assert iscoroutinefunction(sync_to_async(sync_func)) async def async_process(queue):