summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-10-17 15:15:10 +0200
committerGitHub <noreply@github.com>2024-10-17 10:15:10 -0300
commitbd3b1dfa2422e02ced3a894adb7544e42540c97d (patch)
tree51bcde8498f1968f697726092b3e63eea5b17325
parent8b1a3a56438ce99fe9058f078a6bdd92a01e1130 (diff)
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.
-rw-r--r--django/contrib/auth/decorators.py11
-rw-r--r--tests/auth_tests/test_decorators.py2
2 files changed, 6 insertions, 7 deletions
diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py
index 77fbc79855..4d62aec93a 100644
--- a/django/contrib/auth/decorators.py
+++ b/django/contrib/auth/decorators.py
@@ -1,8 +1,7 @@
-import asyncio
from functools import wraps
from urllib.parse import urlsplit
-from asgiref.sync import async_to_sync, sync_to_async
+from asgiref.sync import async_to_sync, iscoroutinefunction, sync_to_async
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
@@ -35,11 +34,11 @@ def user_passes_test(
return redirect_to_login(path, resolved_login_url, redirect_field_name)
- if asyncio.iscoroutinefunction(view_func):
+ if iscoroutinefunction(view_func):
async def _view_wrapper(request, *args, **kwargs):
auser = await request.auser()
- if asyncio.iscoroutinefunction(test_func):
+ if iscoroutinefunction(test_func):
test_pass = await test_func(auser)
else:
test_pass = await sync_to_async(test_func)(auser)
@@ -51,7 +50,7 @@ def user_passes_test(
else:
def _view_wrapper(request, *args, **kwargs):
- if asyncio.iscoroutinefunction(test_func):
+ if iscoroutinefunction(test_func):
test_pass = async_to_sync(test_func)(request.user)
else:
test_pass = test_func(request.user)
@@ -107,7 +106,7 @@ def permission_required(perm, login_url=None, raise_exception=False):
perms = perm
def decorator(view_func):
- if asyncio.iscoroutinefunction(view_func):
+ if iscoroutinefunction(view_func):
async def check_perms(user):
# First check if the user has the permission (even anon users).
diff --git a/tests/auth_tests/test_decorators.py b/tests/auth_tests/test_decorators.py
index fa2672beb4..2c3f93d2ab 100644
--- a/tests/auth_tests/test_decorators.py
+++ b/tests/auth_tests/test_decorators.py
@@ -1,4 +1,4 @@
-from asyncio import iscoroutinefunction
+from asgiref.sync import iscoroutinefunction
from django.conf import settings
from django.contrib.auth import models