From d6f3b5858991e9609eaefc139dc605b36f9a07b3 Mon Sep 17 00:00:00 2001 From: Mateo Radman <48420316+mateoradman@users.noreply.github.com> Date: Sat, 5 Jun 2021 12:46:13 +0200 Subject: [PATCH] Fixed #32810 -- Optimized django.utils.formats.number_format() a bit. Pre-calculate use_l10n for get_format() calls. --- django/utils/formats.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/django/utils/formats.py b/django/utils/formats.py index 3bad64150a..d6eccf6b68 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -171,10 +171,8 @@ def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False): If use_l10n is provided and is not None, it forces the value to be localized (or not), overriding the value of settings.USE_L10N. """ - if use_l10n or (use_l10n is None and settings.USE_L10N): - lang = get_language() - else: - lang = None + use_l10n = use_l10n or (use_l10n is None and settings.USE_L10N) + lang = get_language() if use_l10n else None return numberformat.format( value, get_format('DECIMAL_SEPARATOR', lang, use_l10n=use_l10n),