1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00

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

This commit is contained in:
Sarah Boyce 2024-12-12 17:01:49 +01:00
parent 8081557508
commit 1e331911a8
4 changed files with 6 additions and 21 deletions

View File

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

View File

@ -687,11 +687,6 @@ escaping HTML.
through :func:`conditional_escape` which (ultimately) calls through :func:`conditional_escape` which (ultimately) calls
:func:`~django.utils.encoding.force_str` on the values. :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) .. function:: format_html_join(sep, format_string, args_generator)
A wrapper of :func:`format_html`, for the common case of a group of A wrapper of :func:`format_html`, for the common case of a group of

View File

@ -265,6 +265,9 @@ to remove usage of these features.
* ``request`` is required in the signature of ``ModelAdmin.lookup_allowed()`` * ``request`` is required in the signature of ``ModelAdmin.lookup_allowed()``
subclasses. 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 See :ref:`deprecated-features-5.1` for details on these changes, including how
to remove usage of these features. to remove usage of these features.

View File

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