summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilthans <gilthans@gmail.com>2022-08-23 16:12:03 +0300
committerGilthans <gilthans@gmail.com>2022-08-23 16:12:03 +0300
commitc97f475189c4416489458281a62cb9f80efdd01b (patch)
treec8d996b089b7b5e34c81ce9eed9aaa5b8614f634
parent68bcc05f01585d6f8220346405859d1ce9517b4e (diff)
downloadnatsort-c97f475189c4416489458281a62cb9f80efdd01b.tar.gz
Fixed locale string mypy issue
-rw-r--r--natsort/compat/locale.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/natsort/compat/locale.py b/natsort/compat/locale.py
index b4c5356..66280e5 100644
--- a/natsort/compat/locale.py
+++ b/natsort/compat/locale.py
@@ -38,10 +38,10 @@ try: # noqa: C901
# If using icu, get the locale from the current global locale,
def get_icu_locale() -> str:
- try:
- return cast(str, icu.Locale(".".join(getlocale())))
- except TypeError: # pragma: no cover
+ language_code, encoding = getlocale()
+ if language_code is None or encoding is None: # pragma: no cover
return cast(str, icu.Locale())
+ return icu.Locale(f"{language_code}.{encoding}")
def get_strxfrm() -> TrxfmFunc:
return cast(TrxfmFunc, icu.Collator.createInstance(get_icu_locale()).getSortKey)
@@ -75,10 +75,11 @@ except ImportError:
# characters are incorrectly blank. Here is a lookup table of the
# corrections I am aware of.
if dumb_sort():
- try:
- loc = ".".join(locale.getlocale())
- except TypeError: # No locale loaded, default to ','
+ language_code, encoding = locale.getlocale()
+ if language_code is None or encoding is None:
+ # No locale loaded, default to ','
return ","
+ loc = f"{language_code}.{encoding}"
return {
"de_DE.ISO8859-15": ".",
"es_ES.ISO8859-1": ".",