Browse Source

Refs #34609 -- Removed support for calling format_html() without arguments per deprecation timeline.

Sarah Boyce 3 months ago
parent
commit
1e331911a8
4 changed files with 6 additions and 21 deletions
  1. 1 9
      django/utils/html.py
  2. 0 5
      docs/ref/utils.txt
  3. 3 0
      docs/releases/6.0.txt
  4. 2 7
      tests/utils_tests/test_html.py

+ 1 - 9
django/utils/html.py

@@ -3,13 +3,11 @@
 import html
 import json
 import re
-import warnings
 from collections.abc import Mapping
 from html.parser import HTMLParser
 from urllib.parse import parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit
 
 from django.core.exceptions import SuspiciousOperation
-from django.utils.deprecation import RemovedInDjango60Warning
 from django.utils.encoding import punycode
 from django.utils.functional import Promise, cached_property, keep_lazy, keep_lazy_text
 from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS
@@ -131,13 +129,7 @@ def format_html(format_string, *args, **kwargs):
     of str.format or % interpolation to build up small HTML fragments.
     """
     if not (args or kwargs):
-        # RemovedInDjango60Warning: when the deprecation ends, replace with:
-        # raise TypeError("args or kwargs must be provided.")
-        warnings.warn(
-            "Calling format_html() without passing args or kwargs is deprecated.",
-            RemovedInDjango60Warning,
-            stacklevel=2,
-        )
+        raise TypeError("args or kwargs must be provided.")
     args_safe = map(conditional_escape, args)
     kwargs_safe = {k: conditional_escape(v) for (k, v) in kwargs.items()}
     return mark_safe(format_string.format(*args_safe, **kwargs_safe))

+ 0 - 5
docs/ref/utils.txt

@@ -687,11 +687,6 @@ escaping HTML.
     through :func:`conditional_escape` which (ultimately) calls
     :func:`~django.utils.encoding.force_str` on the values.
 
-    .. deprecated:: 5.0
-
-        Support for calling ``format_html()`` without passing args or kwargs is
-        deprecated.
-
 .. function:: format_html_join(sep, format_string, args_generator)
 
     A wrapper of :func:`format_html`, for the common case of a group of

+ 3 - 0
docs/releases/6.0.txt

@@ -265,6 +265,9 @@ to remove usage of these features.
 * ``request`` is required in the signature of ``ModelAdmin.lookup_allowed()``
   subclasses.
 
+* Support for calling ``format_html()`` without passing args or kwargs is
+  removed.
+
 See :ref:`deprecated-features-5.1` for details on these changes, including how
 to remove usage of these features.
 

+ 2 - 7
tests/utils_tests/test_html.py

@@ -4,7 +4,6 @@ from datetime import datetime
 from django.core.exceptions import SuspiciousOperation
 from django.core.serializers.json import DjangoJSONEncoder
 from django.test import SimpleTestCase
-from django.utils.deprecation import RemovedInDjango60Warning
 from django.utils.functional import lazystr
 from django.utils.html import (
     conditional_escape,
@@ -69,14 +68,10 @@ class TestUtilsHtml(SimpleTestCase):
         )
 
     def test_format_html_no_params(self):
-        msg = "Calling format_html() without passing args or kwargs is deprecated."
-        # RemovedInDjango60Warning: when the deprecation ends, replace with:
-        # msg = "args or kwargs must be provided."
-        # with self.assertRaisesMessage(TypeError, msg):
-        with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
+        msg = "args or kwargs must be provided."
+        with self.assertRaisesMessage(TypeError, msg):
             name = "Adam"
             self.assertEqual(format_html(f"<i>{name}</i>"), "<i>Adam</i>")
-        self.assertEqual(ctx.filename, __file__)
 
     def test_format_html_join_with_positional_arguments(self):
         self.assertEqual(