From 07ebef566f751e172e266165071081c7614e2d33 Mon Sep 17 00:00:00 2001 From: Jimmy Angelakos Date: Mon, 12 Sep 2022 12:59:14 +0200 Subject: [PATCH] Refs #34000 -- Optimized handling None values in numberformat.format(). --- django/utils/numberformat.py | 2 +- tests/utils_tests/test_numberformat.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py index 35bbdd39e1..6e3628ff91 100644 --- a/django/utils/numberformat.py +++ b/django/utils/numberformat.py @@ -25,7 +25,7 @@ def format( module in locale.localeconv() LC_NUMERIC grouping (e.g. (3, 2, 0)). * thousand_sep: Thousand separator symbol (for example ",") """ - if number == "": + if number is None or number == "": return mark_safe(number) use_grouping = ( use_l10n or (use_l10n is None and settings.USE_L10N) diff --git a/tests/utils_tests/test_numberformat.py b/tests/utils_tests/test_numberformat.py index 59fa421682..3c7620c744 100644 --- a/tests/utils_tests/test_numberformat.py +++ b/tests/utils_tests/test_numberformat.py @@ -175,3 +175,4 @@ class TestNumberFormat(SimpleTestCase): def test_empty(self): self.assertEqual(nformat("", "."), "") + self.assertEqual(nformat(None, "."), "None")