From 857f860d5628d9d9a60eb0ab858647211fb8bb01 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Mon, 9 Jul 2018 20:25:11 +0500 Subject: [PATCH] Removed unneded str() calls prior to mark_safe(); simplified mark_safe(). --- django/template/defaultfilters.py | 2 +- django/utils/numberformat.py | 2 +- django/utils/safestring.py | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index ef7ae8679d..53b9ade716 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -448,7 +448,7 @@ def safeseq(value): individually, as safe, after converting them to strings. Return a list with the results. """ - return [mark_safe(str(obj)) for obj in value] + return [mark_safe(obj) for obj in value] @register.filter(is_safe=True) diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py index c6f9af6893..4dc37ae22b 100644 --- a/django/utils/numberformat.py +++ b/django/utils/numberformat.py @@ -23,7 +23,7 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', use_grouping = use_grouping and grouping != 0 # Make the common case fast if isinstance(number, int) and not use_grouping and not decimal_pos: - return mark_safe(str(number)) + return mark_safe(number) # sign sign = '' if isinstance(number, Decimal): diff --git a/django/utils/safestring.py b/django/utils/safestring.py index 2da467a079..5128add622 100644 --- a/django/utils/safestring.py +++ b/django/utils/safestring.py @@ -5,7 +5,7 @@ that the producer of the string has already turned characters that should not be interpreted by the HTML engine (e.g. '<') into the appropriate entities. """ -from django.utils.functional import Promise, wraps +from django.utils.functional import wraps class SafeData: @@ -79,8 +79,6 @@ def mark_safe(s): """ if hasattr(s, '__html__'): return s - if isinstance(s, (str, Promise)): - return SafeText(s) if callable(s): return _safety_decorator(mark_safe, s) - return SafeText(str(s)) + return SafeText(s)