Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django/contrib/auth/decorators.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions django/contrib/auth/middleware.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion django/core/handlers/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion django/core/handlers/exception.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions django/core/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Expand Down Expand Up @@ -266,7 +266,7 @@ async def acount(self):
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)
):
Expand Down
3 changes: 2 additions & 1 deletion django/dispatch/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
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

Expand Down
3 changes: 2 additions & 1 deletion django/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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
Expand All @@ -25,7 +26,7 @@
)
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
Expand Down
3 changes: 1 addition & 2 deletions django/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
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
Expand Down
3 changes: 1 addition & 2 deletions django/utils/decorators.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 2 additions & 1 deletion django/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
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

Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/cache.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/clickjacking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from functools import wraps

from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction


def xframe_options_deny(view_func):
Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from functools import wraps

from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction


def no_append_slash(view_func):
Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/csp.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/csrf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/debug.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import inspect
from functools import wraps

from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction

from django.http import HttpRequest

Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

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
Expand Down
3 changes: 1 addition & 2 deletions django/views/decorators/vary.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 1 addition & 2 deletions django/views/generic/base.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/async.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions docs/topics/http/middleware.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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


Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/admin_changelist/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ def test_exact_lookup_with_more_lenient_formfield(self):
cl = m.get_changelist_instance(request)
self.assertCountEqual(cl.queryset, [obj])

@skipUnlessDBFeature("supports_primitives_in_json_field")
def test_exact_lookup_validates_each_field_independently(self):
"""
Each field validates the search term independently without leaking
Expand Down
3 changes: 2 additions & 1 deletion tests/async/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/auth_tests/test_decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction

from django.conf import settings
from django.contrib.auth import models
Expand Down
3 changes: 1 addition & 2 deletions tests/decorators/test_cache.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/decorators/test_clickjacking.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/decorators/test_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction

from django.http import HttpRequest, HttpResponse
from django.test import SimpleTestCase
Expand Down
3 changes: 1 addition & 2 deletions tests/decorators/test_csp.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/decorators/test_csrf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction

from django.conf import settings
from django.http import HttpRequest, HttpResponse
Expand Down
2 changes: 1 addition & 1 deletion tests/decorators/test_gzip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction

from django.http import HttpRequest, HttpResponse
from django.test import SimpleTestCase
Expand Down
3 changes: 1 addition & 2 deletions tests/decorators/test_http.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/decorators/test_vary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asgiref.sync import iscoroutinefunction
from inspect import iscoroutinefunction

from django.http import HttpRequest, HttpResponse
from django.test import SimpleTestCase
Expand Down
3 changes: 1 addition & 2 deletions tests/decorators/tests.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/middleware_exceptions/middleware.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 11 additions & 1 deletion tests/schema/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3805,8 +3805,14 @@ def test_func_unique_constraint_nondeterministic(self):
with self.assertRaises(DatabaseError):
editor.add_constraint(Author, constraint)

@skipUnlessDBFeature("supports_nulls_distinct_unique_constraints")
@skipUnlessDBFeature(
"supports_expression_indexes", "supports_nulls_distinct_unique_constraints"
)
def test_unique_constraint_index_nulls_distinct(self):
"""
For a UniqueConstraint with expressions, the backend executes:
CREATE UNIQUE INDEX ...
"""
with connection.schema_editor() as editor:
editor.create_model(Author)
nulls_distinct = UniqueConstraint(
Expand All @@ -3831,6 +3837,10 @@ def test_unique_constraint_index_nulls_distinct(self):

@skipUnlessDBFeature("supports_nulls_distinct_unique_constraints")
def test_unique_constraint_nulls_distinct(self):
"""
For UniqueConstraint(fields=...), the backend executes:
ALTER TABLE "schema_author" ADD CONSTRAINT ...
"""
with connection.schema_editor() as editor:
editor.create_model(Author)
constraint = UniqueConstraint(
Expand Down
3 changes: 1 addition & 2 deletions tests/signals/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down