Skip to content

Commit

Permalink
Make use of shim internally.
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson committed Dec 13, 2022
1 parent ef7d542 commit 2103179
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions asgiref/compatibility.py
@@ -1,6 +1,7 @@
import asyncio
import inspect

from .sync import iscoroutinefunction


def is_double_callable(application):
"""
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion asgiref/sync.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_sync.py
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2103179

Please sign in to comment.