mirror of https://github.com/django/django.git
Refs #34609 -- Fixed deprecation warning stack level in format_html().
Co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
parent
b941de340d
commit
2b71b2c8dc
|
@ -130,10 +130,11 @@ def format_html(format_string, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
if not (args or kwargs):
|
if not (args or kwargs):
|
||||||
# RemovedInDjango60Warning: when the deprecation ends, replace with:
|
# RemovedInDjango60Warning: when the deprecation ends, replace with:
|
||||||
# raise ValueError("args or kwargs must be provided.")
|
# raise TypeError("args or kwargs must be provided.")
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Calling format_html() without passing args or kwargs is deprecated.",
|
"Calling format_html() without passing args or kwargs is deprecated.",
|
||||||
RemovedInDjango60Warning,
|
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()}
|
||||||
|
|
|
@ -71,10 +71,11 @@ class TestUtilsHtml(SimpleTestCase):
|
||||||
msg = "Calling format_html() without passing args or kwargs is deprecated."
|
msg = "Calling format_html() without passing args or kwargs is deprecated."
|
||||||
# RemovedInDjango60Warning: when the deprecation ends, replace with:
|
# RemovedInDjango60Warning: when the deprecation ends, replace with:
|
||||||
# msg = "args or kwargs must be provided."
|
# msg = "args or kwargs must be provided."
|
||||||
# with self.assertRaisesMessage(ValueError, msg):
|
# with self.assertRaisesMessage(TypeError, msg):
|
||||||
with self.assertWarnsMessage(RemovedInDjango60Warning, 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(
|
||||||
|
|
Loading…
Reference in New Issue