Skip to content

Commit 9327e5f

Browse files
committed
Mark babel.lists.DEFAULT_LOCALE as deprecated
1 parent af558d4 commit 9327e5f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

babel/lists.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
from __future__ import annotations
1717

18+
import warnings
1819
from collections.abc import Sequence
1920
from typing import TYPE_CHECKING
2021

@@ -23,7 +24,20 @@
2324
if TYPE_CHECKING:
2425
from typing_extensions import Literal
2526

26-
DEFAULT_LOCALE = default_locale()
27+
28+
29+
_DEFAULT_LOCALE = default_locale() # TODO(3.0): Remove this.
30+
31+
32+
def __getattr__(name):
33+
if name == "DEFAULT_LOCALE":
34+
warnings.warn(
35+
"The babel.lists.DEFAULT_LOCALE constant is deprecated and will be removed.",
36+
DeprecationWarning,
37+
stacklevel=2,
38+
)
39+
return _DEFAULT_LOCALE
40+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
2741

2842

2943
def format_list(
@@ -76,7 +90,7 @@ def format_list(
7690
:param style: the style to format the list with. See above for description.
7791
:param locale: the locale. Defaults to the system locale.
7892
"""
79-
locale = Locale.parse(locale or DEFAULT_LOCALE)
93+
locale = Locale.parse(locale or _DEFAULT_LOCALE)
8094
if not lst:
8195
return ''
8296
if len(lst) == 1:

tests/test_lists.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ def test_issue_1098():
3030
# Translation verified using Google Translate. It would add more spacing, but the glyphs are correct.
3131
"1英尺5英寸"
3232
)
33+
34+
35+
def test_lists_default_locale_deprecation():
36+
with pytest.warns(DeprecationWarning):
37+
_ = lists.DEFAULT_LOCALE

0 commit comments

Comments
 (0)