summaryrefslogtreecommitdiff
path: root/django/utils/asyncio.py
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /django/utils/asyncio.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
downloaddjango-9c19aff7c7561e3a82978a272ecdaad40dda5c00.tar.gz
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'django/utils/asyncio.py')
-rw-r--r--django/utils/asyncio.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/django/utils/asyncio.py b/django/utils/asyncio.py
index b8e14f1f68..7e0b439db2 100644
--- a/django/utils/asyncio.py
+++ b/django/utils/asyncio.py
@@ -10,6 +10,7 @@ def async_unsafe(message):
Decorator to mark functions as async-unsafe. Someone trying to access
the function while in an async context will get an error message.
"""
+
def decorator(func):
@wraps(func)
def inner(*args, **kwargs):
@@ -19,15 +20,17 @@ def async_unsafe(message):
except RuntimeError:
pass
else:
- if not os.environ.get('DJANGO_ALLOW_ASYNC_UNSAFE'):
+ if not os.environ.get("DJANGO_ALLOW_ASYNC_UNSAFE"):
raise SynchronousOnlyOperation(message)
# Pass onward.
return func(*args, **kwargs)
+
return inner
+
# If the message is actually a function, then be a no-arguments decorator.
if callable(message):
func = message
- message = 'You cannot call this from an async context - use a thread or sync_to_async.'
+ message = "You cannot call this from an async context - use a thread or sync_to_async."
return decorator(func)
else:
return decorator