From: Aarni Koskela Date: Thu, 30 Jul 2026 06:37:12 +0000 (+0300) Subject: Add localedata.clear_caches() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0c17bb4ac96e9f8e9da159e0d6d76093dc3f201;p=thirdparty%2Fbabel.git Add localedata.clear_caches() --- diff --git a/babel/localedata.py b/babel/localedata.py index 4648e662..0536bc85 100644 --- a/babel/localedata.py +++ b/babel/localedata.py @@ -174,6 +174,14 @@ def load(name: os.PathLike[str] | str, merge_inherited: bool = True) -> dict[str _cache_lock.release() +def clear_caches() -> None: + """ + Clear locale data caches. + """ + with _cache_lock: + _cache.clear() + + def merge(dict1: MutableMapping[Any, Any], dict2: Mapping[Any, Any]) -> None: """Merge the data from `dict2` into the `dict1` dictionary, making copies of nested dictionaries. diff --git a/tests/test_localedata.py b/tests/test_localedata.py index 42810b99..f7e23e51 100644 --- a/tests/test_localedata.py +++ b/tests/test_localedata.py @@ -63,18 +63,17 @@ def test_load(): def test_load_inheritance(monkeypatch): - from babel.localedata import _cache - - _cache.clear() + localedata.clear_caches() localedata.load('hi_Latn') # Must not be ['root', 'hi_Latn'] even though 'hi_Latn' matches the 'lang_Script' # form used by 'nonLikelyScripts'. This is because 'hi_Latn' has an explicit parent locale 'en_IN'. - assert list(_cache.keys()) == ['root', 'en', 'en_001', 'en_IN', 'hi_Latn'] + assert set(localedata._cache) == {'root', 'en', 'en_001', 'en_IN', 'hi_Latn'} + - _cache.clear() + localedata.clear_caches() localedata.load('az_Arab') # Must not include 'az' as 'Arab' is not a likely script for 'az'. - assert list(_cache.keys()) == ['root', 'az_Arab'] + assert set(localedata._cache) == {'root', 'az_Arab'} def test_merge():