From 17fb626443ef7d774470df57c024d41ab87678cd Mon Sep 17 00:00:00 2001 From: Mate Barany Date: Mon, 30 Sep 2024 16:05:43 +0200 Subject: [PATCH] Add type annotations to three classes in qlocalexm2cpp.py Add type annotations to CalendarDataWriter, TestLocaleWriter and LocaleHeaderWriter. Task-number: QTBUG-128634 Change-Id: I2c9168fda9cb79cbef3e7ef32ec67270ce168a1b Reviewed-by: Edward Welbourne (cherry picked from commit a9a5f86a8becb12b9a33fbd92d1bb1c6c5421f45) Reviewed-by: Qt Cherry-pick Bot --- util/locale_database/qlocalexml2cpp.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py index e8048946645..fda8e182ecd 100755 --- a/util/locale_database/qlocalexml2cpp.py +++ b/util/locale_database/qlocalexml2cpp.py @@ -556,7 +556,8 @@ class CalendarDataWriter (LocaleSourceEditor): ' {{' + ','.join(('{:6d}',) * 3 + ('{:5d}',) * 6 + ('{:3d}',) * 6) + ' }},').format - def write(self, calendar, locales, names): + def write(self, calendar: str, locales: dict[tuple[int, int, int], Locale], + names: list[tuple[int, int, int]]) -> None: months_data = StringData('months_data', 16) self.writer.write('static constexpr QCalendarLocale locale_data[] = {\n') @@ -577,7 +578,7 @@ class CalendarDataWriter (LocaleSourceEditor): 'Sizes...' '\n') for key in names: - locale = locales[key] + locale: Locale = locales[key] # Sequence of StringDataToken: try: # Twelve long month names can add up to more than 256 (e.g. kde_TZ: 264) @@ -602,7 +603,7 @@ class CalendarDataWriter (LocaleSourceEditor): class TestLocaleWriter (LocaleSourceEditor): - def localeList(self, locales): + def localeList(self, locales: list[tuple[int, int, int]]) -> None: self.writer.write('const LocaleListItem g_locale_list[] = {\n') from enumdata import language_map, territory_map # TODO: update testlocales/ to include script. @@ -618,19 +619,19 @@ class TestLocaleWriter (LocaleSourceEditor): class LocaleHeaderWriter (SourceFileEditor): - def __init__(self, path, temp, enumify): + def __init__(self, path: Path, temp: Path, enumify: Callable[[str, str], str]) -> None: super().__init__(path, temp) self.__enumify = enumify - def languages(self, languages): + def languages(self, languages: dict[int, tuple[str, str, str]]) -> None: self.__enum('Language', languages, self.__language) self.writer.write('\n') - def territories(self, territories): + def territories(self, territories: dict[int, tuple[str, str, str]]) -> None: self.writer.write(" // ### Qt 7: Rename to Territory\n") self.__enum('Country', territories, self.__territory, 'Territory') - def scripts(self, scripts): + def scripts(self, scripts: dict[int, tuple[str, str, str]]) -> None: self.__enum('Script', scripts, self.__script) self.writer.write('\n') @@ -639,13 +640,15 @@ class LocaleHeaderWriter (SourceFileEditor): territory_aliases as __territory, script_aliases as __script) - def __enum(self, name, book, alias, suffix = None): + def __enum(self, name: str, book: dict[int, tuple[str, str, str]], + alias: dict[str, str], suffix: str = None) -> None: assert book if suffix is None: suffix = name - out, enumify = self.writer.write, self.__enumify + out: Callable[[str], int] = self.writer.write + enumify: Callable[[str, str], str] = self.__enumify out(f' enum {name} : ushort {{\n') for key, value in book.items(): member = enumify(value[0], suffix)