mirror of
https://github.com/django/django.git
synced 2026-02-09 02:49:25 +08:00
Refs #34118 -- Removed asgiref coroutine detection shims.
As Python 3.12 is now the floor, we can drop the shims and use the `inspect` module.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from functools import wraps
|
||||
from inspect import iscoroutinefunction
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from asgiref.sync import async_to_sync, iscoroutinefunction, sync_to_async
|
||||
from asgiref.sync import async_to_sync, sync_to_async
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from functools import partial
|
||||
from inspect import iscoroutinefunction, markcoroutinefunction
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import auth
|
||||
from django.contrib.auth import REDIRECT_FIELD_NAME, load_backend
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import types
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from asgiref.sync import async_to_sync, iscoroutinefunction, sync_to_async
|
||||
from asgiref.sync import async_to_sync, sync_to_async
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured, MiddlewareNotUsed
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import logging
|
||||
import sys
|
||||
from functools import wraps
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, sync_to_async
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import signals
|
||||
|
||||
@@ -3,7 +3,7 @@ import inspect
|
||||
import warnings
|
||||
from math import ceil
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, sync_to_async
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
from django.utils.deprecation import RemovedInDjango70Warning
|
||||
from django.utils.functional import cached_property
|
||||
@@ -266,7 +266,7 @@ class AsyncPaginator(BasePaginator):
|
||||
return self._cache_acount
|
||||
c = getattr(self.object_list, "acount", None)
|
||||
if (
|
||||
iscoroutinefunction(c)
|
||||
inspect.iscoroutinefunction(c)
|
||||
and not inspect.isbuiltin(c)
|
||||
and method_has_no_args(c)
|
||||
):
|
||||
|
||||
@@ -3,8 +3,9 @@ import contextvars
|
||||
import logging
|
||||
import threading
|
||||
import weakref
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from asgiref.sync import async_to_sync, iscoroutinefunction, sync_to_async
|
||||
from asgiref.sync import async_to_sync, sync_to_async
|
||||
|
||||
from django.utils.inspect import func_accepts_kwargs
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from contextlib import contextmanager
|
||||
from copy import copy, deepcopy
|
||||
from difflib import get_close_matches
|
||||
from functools import wraps
|
||||
from inspect import iscoroutinefunction
|
||||
from unittest import mock
|
||||
from unittest.suite import _DebugResult
|
||||
from unittest.util import safe_repr
|
||||
@@ -25,7 +26,7 @@ from urllib.parse import (
|
||||
)
|
||||
from urllib.request import url2pathname
|
||||
|
||||
from asgiref.sync import async_to_sync, iscoroutinefunction
|
||||
from asgiref.sync import async_to_sync
|
||||
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
|
||||
@@ -8,14 +8,13 @@ import time
|
||||
import warnings
|
||||
from contextlib import contextmanager
|
||||
from functools import wraps
|
||||
from inspect import iscoroutinefunction
|
||||
from io import StringIO
|
||||
from itertools import chain
|
||||
from types import SimpleNamespace
|
||||
from unittest import TestCase, skipIf, skipUnless
|
||||
from xml.dom.minidom import Node, parseString
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
|
||||
from django.apps import apps
|
||||
from django.apps.registry import Apps
|
||||
from django.conf import UserSettingsHolder, settings
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"Functions that help with dynamically creating decorators for views."
|
||||
|
||||
from functools import partial, update_wrapper, wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
|
||||
from inspect import iscoroutinefunction, markcoroutinefunction
|
||||
|
||||
|
||||
class classonlymethod(classmethod):
|
||||
|
||||
@@ -3,8 +3,9 @@ import inspect
|
||||
import os
|
||||
import warnings
|
||||
from collections import Counter
|
||||
from inspect import iscoroutinefunction, markcoroutinefunction
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction, sync_to_async
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
import django
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.middleware.cache import CacheMiddleware
|
||||
from django.utils.cache import add_never_cache_headers, patch_cache_control
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
|
||||
def xframe_options_deny(view_func):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
|
||||
def no_append_slash(view_func):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
|
||||
def _make_csp_decorator(config_attr_name, config_attr_value):
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.middleware.csrf import CsrfViewMiddleware, get_token
|
||||
from django.utils.decorators import decorator_from_middleware
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import inspect
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ Decorators for views based on HTTP headers.
|
||||
|
||||
import datetime
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpResponseNotAllowed
|
||||
from django.middleware.http import ConditionalGetMiddleware
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.utils.cache import patch_vary_headers
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import logging
|
||||
from inspect import iscoroutinefunction, markcoroutinefunction
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.http import (
|
||||
HttpResponse,
|
||||
|
||||
@@ -28,9 +28,9 @@ class-based view, this means declaring the HTTP method handlers, such as
|
||||
|
||||
.. note::
|
||||
|
||||
Django uses ``asgiref.sync.iscoroutinefunction`` to test if your view is
|
||||
Django uses ``inspect.iscoroutinefunction`` to test if your view is
|
||||
asynchronous or not. If you implement your own method of returning a
|
||||
coroutine, ensure you use ``asgiref.sync.markcoroutinefunction`` so this
|
||||
coroutine, ensure you use ``inspect.markcoroutinefunction`` so this
|
||||
function returns ``True``.
|
||||
|
||||
Under a WSGI server, async views will run in their own, one-off event loop.
|
||||
|
||||
@@ -318,7 +318,7 @@ If your middleware has both ``sync_capable = True`` and
|
||||
``async_capable = True``, then Django will pass it the request without
|
||||
converting it. In this case, you can work out if your middleware will receive
|
||||
async requests by checking if the ``get_response`` object you are passed is a
|
||||
coroutine function, using ``asgiref.sync.iscoroutinefunction``.
|
||||
coroutine function, using ``inspect.iscoroutinefunction``.
|
||||
|
||||
The ``django.utils.decorators`` module contains
|
||||
:func:`~django.utils.decorators.sync_only_middleware`,
|
||||
@@ -337,7 +337,7 @@ at an additional performance penalty.
|
||||
|
||||
Here's an example of how to create a middleware function that supports both::
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
from django.utils.decorators import sync_and_async_middleware
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ Here's an example of how to create a middleware function that supports both::
|
||||
When using an asynchronous class-based middleware, you must ensure that
|
||||
instances are correctly marked as coroutine functions::
|
||||
|
||||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
|
||||
from inspect import iscoroutinefunction, markcoroutinefunction
|
||||
|
||||
|
||||
class AsyncMiddleware:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import asyncio
|
||||
import os
|
||||
from inspect import iscoroutinefunction
|
||||
from unittest import mock
|
||||
|
||||
from asgiref.sync import async_to_sync, iscoroutinefunction
|
||||
from asgiref.sync import async_to_sync
|
||||
|
||||
from django.core.cache import DEFAULT_CACHE_ALIAS, caches
|
||||
from django.core.exceptions import ImproperlyConfigured, SynchronousOnlyOperation
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import models
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from inspect import iscoroutinefunction
|
||||
from unittest import mock
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.decorators import method_decorator
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.middleware.clickjacking import XFrameOptionsMiddleware
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from inspect import iscoroutinefunction
|
||||
from itertools import product
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.csp import CSP
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import datetime
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
from inspect import iscoroutinefunction
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import asyncio
|
||||
from functools import update_wrapper, wraps
|
||||
from inspect import iscoroutinefunction
|
||||
from unittest import TestCase
|
||||
|
||||
from asgiref.sync import iscoroutinefunction
|
||||
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.contrib.auth.decorators import (
|
||||
login_required,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
|
||||
from inspect import iscoroutinefunction, markcoroutinefunction
|
||||
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.template import engines
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import contextvars
|
||||
from inspect import markcoroutinefunction
|
||||
from unittest import mock
|
||||
|
||||
from asgiref.sync import markcoroutinefunction
|
||||
|
||||
from django import dispatch
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
|
||||
Reference in New Issue
Block a user