Currently `_cache` is only populated on `load`, this is an issue with
code which do a lot of locale parsing / instantiation but for one
reason or an other rarely end up needing to actually load the locale
data (e.g. date formatting with non-locale-dependent patterns) because
every cache miss is an `os.path.exists`.
Cache `exists` separately.
Update test because `lru_cache` requires all parameters to be
hashable and a list is not that.
return os.path.join(_dirname, f"{name}.dat")
+@lru_cache(maxsize=None)
def exists(name: str) -> bool:
"""Check whether locale data is available for the given locale.
if name in _cache:
return True
file_found = os.path.exists(resolve_locale_filename(name))
- return True if file_found else bool(normalize_locale(name))
+ return file_found or bool(normalize_locale(name))
@lru_cache(maxsize=None)
assert normalized_locale is None
assert not localedata.exists(None)
- # Testing list input.
+ # Testing tuple input.
normalized_locale = localedata.normalize_locale(['en_us', None])
assert normalized_locale is None
- assert not localedata.exists(['en_us', None])
+ assert not localedata.exists(('en_us', None))
def test_locale_identifiers_cache(monkeypatch):