]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
babel.core: Fix some mypy-discovered issues
authorAarni Koskela <akx@iki.fi>
Wed, 1 Mar 2023 07:13:41 +0000 (09:13 +0200)
committerAarni Koskela <akx@iki.fi>
Wed, 1 Mar 2023 07:31:17 +0000 (09:31 +0200)
babel/core.py

index 4cceba933c82be9fcbc0452cfc735dca215506b6..69f792d3991c85aa7703aa7bd3ee1b129cb61b34 100644 (file)
@@ -197,7 +197,7 @@ class Locale:
         self.variant = variant
         #: the modifier
         self.modifier = modifier
-        self.__data = None
+        self.__data: localedata.LocaleDataDict | None = None
 
         identifier = str(self)
         identifier_without_modifier = identifier.partition('@')[0]
@@ -260,6 +260,7 @@ class Locale:
                                       aliases=aliases)
         if identifier:
             return Locale.parse(identifier, sep=sep)
+        return None
 
     @classmethod
     def parse(
@@ -459,9 +460,9 @@ class Locale:
                 details.append(locale.variants.get(self.variant))
             if self.modifier:
                 details.append(self.modifier)
-            details = filter(None, details)
-            if details:
-                retval += f" ({', '.join(details)})"
+            detail_string = ', '.join(atom for atom in details if atom)
+            if detail_string:
+                retval += f" ({detail_string})"
         return retval
 
     display_name = property(get_display_name, doc="""\
@@ -1071,6 +1072,7 @@ def default_locale(category: str | None = None, aliases: Mapping[str, str] = LOC
                 return get_locale_identifier(parse_locale(locale))
             except ValueError:
                 pass
+    return None
 
 
 def negotiate_locale(preferred: Iterable[str], available: Iterable[str], sep: str = '_', aliases: Mapping[str, str] = LOCALE_ALIASES) -> str | None: