mirror of
https://github.com/django/django.git
synced 2025-01-18 14:24:39 +00:00
Refs #34609 -- Removed support for calling format_html() without arguments per deprecation timeline.
This commit is contained in:
parent
8081557508
commit
1e331911a8
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user