diff options
| author | Mate Barany <[email protected]> | 2024-09-13 17:23:37 +0200 | 
|---|---|---|
| committer | Mate Barany <[email protected]> | 2024-10-16 14:20:02 +0200 | 
| commit | bd475ddf47e33535c2b79367c8850cd611089e3c (patch) | |
| tree | a27f5401daecccc224aa5f88cd1ab2da2facfa90 /util | |
| parent | 93136f7c55e545598a10e617f4951094bdbca9ff (diff) | |
Add type annotations to LocaleKeySorter
Task-number: QTBUG-128634
Pick-to: 6.8
Change-Id: I9a4261746cac029b0abf26fbd03b1915a0035147
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
Diffstat (limited to 'util')
| -rw-r--r-- | util/locale_database/qlocalexml.py | 3 | ||||
| -rwxr-xr-x | util/locale_database/qlocalexml2cpp.py | 15 | 
2 files changed, 10 insertions, 8 deletions
diff --git a/util/locale_database/qlocalexml.py b/util/locale_database/qlocalexml.py index f9f2ba3d577..6a09a18b32a 100644 --- a/util/locale_database/qlocalexml.py +++ b/util/locale_database/qlocalexml.py @@ -19,6 +19,7 @@ You can download jing from https://relaxng.org/jclark/jing.html if your  package manager lacks the jing package.  """ +from typing import Iterator  from xml.sax.saxutils import escape  from localetools import Error, qtVersion @@ -261,7 +262,7 @@ class QLocaleXmlReader (object):                  what.args += (have, give)                  raise -    def defaultMap(self): +    def defaultMap(self) -> Iterator[tuple[tuple[int, int], int]]:          """Map language and script to their default territory by ID.          Yields ((language, script), territory) wherever the likely diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py index b448538539b..500f8935fdb 100755 --- a/util/locale_database/qlocalexml2cpp.py +++ b/util/locale_database/qlocalexml2cpp.py @@ -17,7 +17,7 @@ The ISO 639-3 data file can be downloaded from the SIL website:  import datetime  import argparse  from pathlib import Path -from typing import Optional +from typing import Iterator, Optional  from qlocalexml import QLocaleXmlReader  from localetools import * @@ -55,12 +55,12 @@ class LocaleKeySorter:      # QLocale's likely sub-tag matching algorithms. Make sure this is      # sorting in an order compatible with those algorithms. -    def __init__(self, defaults): -        self.map = dict(defaults) -    def foreign(self, key): -        default = self.map.get(key[:2]) +    def __init__(self, defaults: Iterator[tuple[tuple[int, int], int]]) -> None: +        self.map: dict[tuple[int, int], int] = dict(defaults) +    def foreign(self, key: tuple[int, int, int]) -> bool: +        default: int | None = self.map.get(key[:2])          return default is None or default != key[2] -    def __call__(self, key): +    def __call__(self, key: tuple[int, int, int]) -> tuple[int, bool, int, int]:          # TODO: should we compare territory before or after script ?          return (key[0], self.foreign(key)) + key[1:] @@ -1010,7 +1010,8 @@ def main(argv, out, err):      reader = QLocaleXmlReader(qlocalexml)      locale_map = dict(reader.loadLocaleMap(calendars, err.write))      reader.pruneZoneNaming(locale_map, mutter) -    locale_keys = sorted(locale_map.keys(), key=LocaleKeySorter(reader.defaultMap())) +    locale_keys: list[tuple[int, int, int]] = sorted(locale_map.keys(), +                                                     key=LocaleKeySorter(reader.defaultMap()))      code_data = LanguageCodeData(args.iso_path)  | 
