Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion babel/localedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def __getitem__(self, key: str | int | None) -> Any:
val = alias.resolve(self.base).copy()
merge(val, others)
if isinstance(val, dict): # Return a nested alias-resolving dict
val = LocaleDataDict(val, base=self.base)
return LocaleDataDict(val, base=self.base)
Comment on lines 271 to +272
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... This line has been the same ever since this code was added in 4a6c0f5 in 2008. It's curious that this bug has lurked in here for nearly two decades? I wonder how/if this will affect performance, since we'd no longer be caching this LocaleDataDict below?

Further, from the PR description:

the resolved LocaleDataDict wrapper was memoized back into the underlying cached locale data

Why wouldn't that be that locale's cached locale data? What's the mechanism for it to be in, presumably, another locale's cached data?

if val is not orig:
self._data[key] = val
return val
Expand Down
19 changes: 18 additions & 1 deletion tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import freezegun
import pytest

from babel import Locale, dates
from babel import Locale, dates, localedata
from babel.dates import NO_INHERITANCE_MARKER, UTC, _localize, parse_pattern
from babel.util import FixedOffsetTimezone

Expand Down Expand Up @@ -561,6 +561,23 @@ def test_format_date():
"Sun, Apr 1, '07")


@pytest.mark.parametrize(
('locale', 'expected'),
[
('de', 'Oktober'),
('he', 'אוקטובר'),
('no', 'oktober'),
('fr', 'octobre'),
],
)
def test_format_date_standalone_month_name_isolation(locale, expected):
localedata._cache.clear()
d = date(2025, 10, 1)

assert dates.format_date(d, 'LLLL', locale='he') == 'אוקטובר'
assert dates.format_date(d, 'LLLL', locale=locale) == expected


def test_format_datetime(timezone_getter):
dt = datetime(2007, 4, 1, 15, 30)
assert (dates.format_datetime(dt, locale='en_US') ==
Expand Down