Skip to content

Commit a6a4ca4

Browse files
committed
Make use of shim internally.
1 parent ef7d542 commit a6a4ca4

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

asgiref/compatibility.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import asyncio
21
import inspect
32

3+
from .sync import iscoroutinefunction
4+
45

56
def is_double_callable(application):
67
"""
@@ -18,10 +19,10 @@ def is_double_callable(application):
1819
if hasattr(application, "__call__"):
1920
# We only check to see if its __call__ is a coroutine function -
2021
# if it's not, it still might be a coroutine function itself.
21-
if asyncio.iscoroutinefunction(application.__call__):
22+
if iscoroutinefunction(application.__call__):
2223
return False
2324
# Non-classes we just check directly
24-
return not asyncio.iscoroutinefunction(application)
25+
return not iscoroutinefunction(application)
2526

2627

2728
def double_to_single_callable(application):

asgiref/sync.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def __init__(
378378
self.func = func
379379
functools.update_wrapper(self, func)
380380
self._thread_sensitive = thread_sensitive
381-
self._is_coroutine = asyncio.coroutines._is_coroutine # type: ignore
381+
markcoroutinefunction(self)
382382
if thread_sensitive and executor is not None:
383383
raise TypeError("executor must not be set when thread_sensitive is True")
384384
self._executor = executor

tests/test_sync.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
import pytest
1212

13-
from asgiref.sync import ThreadSensitiveContext, async_to_sync, sync_to_async
13+
from asgiref.sync import (
14+
ThreadSensitiveContext,
15+
async_to_sync,
16+
iscoroutinefunction,
17+
sync_to_async,
18+
)
1419
from asgiref.timeout import timeout
1520

1621

@@ -645,8 +650,8 @@ def test_sync_to_async_detected_as_coroutinefunction():
645650
def sync_func():
646651
return
647652

648-
assert not asyncio.iscoroutinefunction(sync_to_async)
649-
assert asyncio.iscoroutinefunction(sync_to_async(sync_func))
653+
assert not iscoroutinefunction(sync_to_async)
654+
assert iscoroutinefunction(sync_to_async(sync_func))
650655

651656

652657
async def async_process(queue):

0 commit comments

Comments
 (0)