]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Mark `babel.lists.DEFAULT_LOCALE` as deprecated 1164/head
authorAarni Koskela <akx@iki.fi>
Thu, 9 Jan 2025 08:30:09 +0000 (10:30 +0200)
committerAarni Koskela <akx@iki.fi>
Thu, 9 Jan 2025 12:35:40 +0000 (14:35 +0200)
babel/lists.py
tests/test_lists.py

index 60590d6c9ccb8ebde8cd6d6459bc26536bdd8c73..f1d3790d18244ff6c0f7b31d39a819e56a491fd4 100644 (file)
@@ -15,6 +15,7 @@
 """
 from __future__ import annotations
 
+import warnings
 from collections.abc import Sequence
 from typing import TYPE_CHECKING
 
@@ -23,7 +24,20 @@ from babel.core import Locale, default_locale
 if TYPE_CHECKING:
     from typing_extensions import Literal
 
-DEFAULT_LOCALE = default_locale()
+
+
+_DEFAULT_LOCALE = default_locale()  # TODO(3.0): Remove this.
+
+
+def __getattr__(name):
+    if name == "DEFAULT_LOCALE":
+        warnings.warn(
+            "The babel.lists.DEFAULT_LOCALE constant is deprecated and will be removed.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
+        return _DEFAULT_LOCALE
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
 
 
 def format_list(
@@ -76,7 +90,7 @@ def format_list(
     :param style: the style to format the list with. See above for description.
     :param locale: the locale. Defaults to the system locale.
     """
-    locale = Locale.parse(locale or DEFAULT_LOCALE)
+    locale = Locale.parse(locale or _DEFAULT_LOCALE)
     if not lst:
         return ''
     if len(lst) == 1:
index 46ca10d0264a3878a2094130bc39558347006952..ef522f223ff8dd77694e8c7e77025147585407f9 100644 (file)
@@ -30,3 +30,8 @@ def test_issue_1098():
         # Translation verified using Google Translate. It would add more spacing, but the glyphs are correct.
         "1英尺5英寸"
     )
+
+
+def test_lists_default_locale_deprecation():
+    with pytest.warns(DeprecationWarning):
+        _ = lists.DEFAULT_LOCALE