Skip to content

Commit

Permalink
Mark babel.lists.DEFAULT_LOCALE as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jan 9, 2025
1 parent 67c2282 commit 458b10c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions babel/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
from __future__ import annotations

import warnings
from collections.abc import Sequence
from typing import TYPE_CHECKING

Expand All @@ -23,7 +24,20 @@
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(
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 458b10c

Please sign in to comment.