diff --git a/babel/localedata.py b/babel/localedata.py index 2b225a142..4648e6626 100644 --- a/babel/localedata.py +++ b/babel/localedata.py @@ -60,6 +60,7 @@ def resolve_locale_filename(name: os.PathLike[str] | str) -> str: 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. @@ -72,7 +73,7 @@ def exists(name: str) -> bool: 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) diff --git a/tests/test_localedata.py b/tests/test_localedata.py index 03cbed1dc..42810b992 100644 --- a/tests/test_localedata.py +++ b/tests/test_localedata.py @@ -109,10 +109,10 @@ def test_locale_argument_acceptance(): 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):