]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add localedata.clear_caches()
authorAarni Koskela <akx@iki.fi>
Thu, 30 Jul 2026 06:37:12 +0000 (09:37 +0300)
committerAarni Koskela <akx@iki.fi>
Thu, 30 Jul 2026 10:17:18 +0000 (13:17 +0300)
babel/localedata.py
tests/test_localedata.py

index 4648e66266c93616c42a1a9707fc87dd609825bf..0536bc852241af0028615a927abb6c5a489abb90 100644 (file)
@@ -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.
index 42810b992b46369876d7f963d0b69b02f788c0ac..f7e23e51663bef1c4a72a3204b72aa57c44ca81b 100644 (file)
@@ -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():