From 1e331911a88f289f52e3d81340e209d0b78abdbb Mon Sep 17 00:00:00 2001
From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Date: Thu, 12 Dec 2024 17:01:49 +0100
Subject: [PATCH] Refs #34609 -- Removed support for calling format_html()
without arguments per deprecation timeline.
---
django/utils/html.py | 10 +---------
docs/ref/utils.txt | 5 -----
docs/releases/6.0.txt | 3 +++
tests/utils_tests/test_html.py | 9 ++-------
4 files changed, 6 insertions(+), 21 deletions(-)
diff --git a/django/utils/html.py b/django/utils/html.py
index 10036c38c4..310742afe1 100644
--- a/django/utils/html.py
+++ b/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))
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index 72e7eb31c8..3f72672622 100644
--- a/docs/ref/utils.txt
+++ b/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
diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt
index 865c11b47b..5a58dcf599 100644
--- a/docs/releases/6.0.txt
+++ b/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.
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index 0beaf98bff..88bfa24925 100644
--- a/tests/utils_tests/test_html.py
+++ b/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"{name}"), "Adam")
- self.assertEqual(ctx.filename, __file__)
def test_format_html_join_with_positional_arguments(self):
self.assertEqual(