summaryrefslogtreecommitdiff
path: root/django/conf/__init__.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2021-09-09 07:42:05 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-14 12:05:43 +0200
commit676bd084f2509f4201561d5c77ed4ecbd157bfa0 (patch)
treebc8dfe6748a6bfc5fe8c728a5f825dfff575cb56 /django/conf/__init__.py
parent04e023e38331d6717af1cbd8da4926af612f7831 (diff)
Fixed #32873 -- Deprecated settings.USE_L10N.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django/conf/__init__.py')
-rw-r--r--django/conf/__init__.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 628b1f7e4d..f8018f723b 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -9,9 +9,11 @@ for a list of all possible variables.
import importlib
import os
import time
+import traceback
import warnings
from pathlib import Path
+import django
from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.deprecation import RemovedInDjango50Warning
@@ -19,6 +21,12 @@ from django.utils.functional import LazyObject, empty
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
+USE_L10N_DEPRECATED_MSG = (
+ 'The USE_L10N setting is deprecated. Starting with Django 5.0, localized '
+ 'formatting of data will always be enabled. For example Django will '
+ 'display numbers and dates using the format of the current locale.'
+)
+
class SettingsReference(str):
"""
@@ -129,6 +137,27 @@ class LazySettings(LazyObject):
"""Return True if the settings have already been configured."""
return self._wrapped is not empty
+ @property
+ def USE_L10N(self):
+ stack = traceback.extract_stack()
+ # Show a warning if the setting is used outside of Django.
+ # Stack index: -1 this line, -2 the caller.
+ filename, _, _, _ = stack[-2]
+ if not filename.startswith(os.path.dirname(django.__file__)):
+ warnings.warn(
+ USE_L10N_DEPRECATED_MSG,
+ RemovedInDjango50Warning,
+ stacklevel=2,
+ )
+ return self.__getattr__('USE_L10N')
+
+ # RemovedInDjango50Warning.
+ @property
+ def _USE_L10N_INTERNAL(self):
+ # Special hook to avoid checking a traceback in internal use on hot
+ # paths.
+ return self.__getattr__('USE_L10N')
+
class Settings:
def __init__(self, settings_module):
@@ -179,6 +208,9 @@ class Settings:
os.environ['TZ'] = self.TIME_ZONE
time.tzset()
+ if self.is_overridden('USE_L10N'):
+ warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning)
+
def is_overridden(self, setting):
return setting in self._explicit_settings
@@ -210,6 +242,8 @@ class UserSettingsHolder:
def __setattr__(self, name, value):
self._deleted.discard(name)
+ if name == 'USE_L10N':
+ warnings.warn(USE_L10N_DEPRECATED_MSG, RemovedInDjango50Warning)
super().__setattr__(name, value)
def __delattr__(self, name):