Skip to content

Commit afe8464

Browse files
author
Funan Zhou
committed
Fix standalone month alias cache leakage
1 parent dea267e commit afe8464

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

babel/localedata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def __getitem__(self, key: str | int | None) -> Any:
269269
val = alias.resolve(self.base).copy()
270270
merge(val, others)
271271
if isinstance(val, dict): # Return a nested alias-resolving dict
272-
val = LocaleDataDict(val, base=self.base)
272+
return LocaleDataDict(val, base=self.base)
273273
if val is not orig:
274274
self._data[key] = val
275275
return val

tests/test_dates.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import freezegun
1717
import pytest
1818

19-
from babel import Locale, dates
19+
from babel import Locale, dates, localedata
2020
from babel.dates import NO_INHERITANCE_MARKER, UTC, _localize, parse_pattern
2121
from babel.util import FixedOffsetTimezone
2222

@@ -561,6 +561,23 @@ def test_format_date():
561561
"Sun, Apr 1, '07")
562562

563563

564+
@pytest.mark.parametrize(
565+
('locale', 'expected'),
566+
[
567+
('de', 'Oktober'),
568+
('he', 'אוקטובר'),
569+
('no', 'oktober'),
570+
('fr', 'octobre'),
571+
],
572+
)
573+
def test_format_date_standalone_month_name_isolation(locale, expected):
574+
localedata._cache.clear()
575+
d = date(2025, 10, 1)
576+
577+
assert dates.format_date(d, 'LLLL', locale='he') == 'אוקטובר'
578+
assert dates.format_date(d, 'LLLL', locale=locale) == expected
579+
580+
564581
def test_format_datetime(timezone_getter):
565582
dt = datetime(2007, 4, 1, 15, 30)
566583
assert (dates.format_datetime(dt, locale='en_US') ==

0 commit comments

Comments
 (0)