summaryrefslogtreecommitdiff
path: root/django/utils/deprecation.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/deprecation.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'django/utils/deprecation.py')
-rw-r--r--django/utils/deprecation.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
index 48209bcdf1..528783a5c1 100644
--- a/django/utils/deprecation.py
+++ b/django/utils/deprecation.py
@@ -14,7 +14,9 @@ class RemovedInDjango50Warning(PendingDeprecationWarning):
class warn_about_renamed_method:
- def __init__(self, class_name, old_method_name, new_method_name, deprecation_warning):
+ def __init__(
+ self, class_name, old_method_name, new_method_name, deprecation_warning
+ ):
self.class_name = class_name
self.old_method_name = old_method_name
self.new_method_name = new_method_name
@@ -23,10 +25,13 @@ class warn_about_renamed_method:
def __call__(self, f):
def wrapped(*args, **kwargs):
warnings.warn(
- "`%s.%s` is deprecated, use `%s` instead." %
- (self.class_name, self.old_method_name, self.new_method_name),
- self.deprecation_warning, 2)
+ "`%s.%s` is deprecated, use `%s` instead."
+ % (self.class_name, self.old_method_name, self.new_method_name),
+ self.deprecation_warning,
+ 2,
+ )
return f(*args, **kwargs)
+
return wrapped
@@ -60,9 +65,11 @@ class RenameMethodsBase(type):
# Define the new method if missing and complain about it
if not new_method and old_method:
warnings.warn(
- "`%s.%s` method should be renamed `%s`." %
- (class_name, old_method_name, new_method_name),
- deprecation_warning, 2)
+ "`%s.%s` method should be renamed `%s`."
+ % (class_name, old_method_name, new_method_name),
+ deprecation_warning,
+ 2,
+ )
setattr(base, new_method_name, old_method)
setattr(base, old_method_name, wrapper(old_method))
@@ -77,7 +84,8 @@ class DeprecationInstanceCheck(type):
def __instancecheck__(self, instance):
warnings.warn(
"`%s` is deprecated, use `%s` instead." % (self.__name__, self.alternative),
- self.deprecation_warning, 2
+ self.deprecation_warning,
+ 2,
)
return super().__instancecheck__(instance)
@@ -88,17 +96,17 @@ class MiddlewareMixin:
def __init__(self, get_response):
if get_response is None:
- raise ValueError('get_response must be provided.')
+ raise ValueError("get_response must be provided.")
self.get_response = get_response
self._async_check()
super().__init__()
def __repr__(self):
- return '<%s get_response=%s>' % (
+ return "<%s get_response=%s>" % (
self.__class__.__qualname__,
getattr(
self.get_response,
- '__qualname__',
+ "__qualname__",
self.get_response.__class__.__name__,
),
)
@@ -120,10 +128,10 @@ class MiddlewareMixin:
if self._is_coroutine:
return self.__acall__(request)
response = None
- if hasattr(self, 'process_request'):
+ if hasattr(self, "process_request"):
response = self.process_request(request)
response = response or self.get_response(request)
- if hasattr(self, 'process_response'):
+ if hasattr(self, "process_response"):
response = self.process_response(request, response)
return response
@@ -133,13 +141,13 @@ class MiddlewareMixin:
is running.
"""
response = None
- if hasattr(self, 'process_request'):
+ if hasattr(self, "process_request"):
response = await sync_to_async(
self.process_request,
thread_sensitive=True,
)(request)
response = response or await self.get_response(request)
- if hasattr(self, 'process_response'):
+ if hasattr(self, "process_response"):
response = await sync_to_async(
self.process_response,
thread_sensitive=True,