Skip to content

Commit bd3b1df

Browse files
authored
Refs #35844 -- Used asgiref.sync.iscoroutinefunction() instead of deprecated asyncio.iscoroutinefunction().
Fixes DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead.
1 parent 8b1a3a5 commit bd3b1df

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

django/contrib/auth/decorators.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import asyncio
21
from functools import wraps
32
from urllib.parse import urlsplit
43

5-
from asgiref.sync import async_to_sync, sync_to_async
4+
from asgiref.sync import async_to_sync, iscoroutinefunction, sync_to_async
65

76
from django.conf import settings
87
from django.contrib.auth import REDIRECT_FIELD_NAME
@@ -35,11 +34,11 @@ def _redirect_to_login(request):
3534

3635
return redirect_to_login(path, resolved_login_url, redirect_field_name)
3736

38-
if asyncio.iscoroutinefunction(view_func):
37+
if iscoroutinefunction(view_func):
3938

4039
async def _view_wrapper(request, *args, **kwargs):
4140
auser = await request.auser()
42-
if asyncio.iscoroutinefunction(test_func):
41+
if iscoroutinefunction(test_func):
4342
test_pass = await test_func(auser)
4443
else:
4544
test_pass = await sync_to_async(test_func)(auser)
@@ -51,7 +50,7 @@ async def _view_wrapper(request, *args, **kwargs):
5150
else:
5251

5352
def _view_wrapper(request, *args, **kwargs):
54-
if asyncio.iscoroutinefunction(test_func):
53+
if iscoroutinefunction(test_func):
5554
test_pass = async_to_sync(test_func)(request.user)
5655
else:
5756
test_pass = test_func(request.user)
@@ -107,7 +106,7 @@ def permission_required(perm, login_url=None, raise_exception=False):
107106
perms = perm
108107

109108
def decorator(view_func):
110-
if asyncio.iscoroutinefunction(view_func):
109+
if iscoroutinefunction(view_func):
111110

112111
async def check_perms(user):
113112
# First check if the user has the permission (even anon users).

tests/auth_tests/test_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from asyncio import iscoroutinefunction
1+
from asgiref.sync import iscoroutinefunction
22

33
from django.conf import settings
44
from django.contrib.auth import models

0 commit comments

Comments
 (0)