Skip to content

Commit

Permalink
Correct some type-annotations in util/locale_database/
Browse files Browse the repository at this point in the history
Amends commit 3b541da to deal with
likely subtags being handled as tuples of enum names, rather than as
tuples of their numeric values. The change from names to value went to
6.9 (commit bd5bb70) but isn't picked
back to 6.8 or earlier. However, the type annotations done on 6.9
after that were picked back to 6.8 and I missed this twist in review.

Task-number: QTBUG-129613
Change-Id: I35eb21d26db1ff0537ecaf5e727431a16c6443c4
Reviewed-by: Mate Barany <[email protected]>
  • Loading branch information
ediosyncratic committed Dec 6, 2024
1 parent 948599e commit 34f6bf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions util/locale_database/cldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def __init__(self, root: Path, grumble: Callable[[str], int] = lambda msg: 0,
self.whitter, self.grumble = whitter, grumble
self.root.checkEnumData(grumble)

def likelySubTags(self) -> Iterator[tuple[tuple[int, int, int, int],
tuple[int, int, int, int]]]:
def likelySubTags(self) -> Iterator[tuple[tuple[str, str, str, str],
tuple[str, str, str, str]]]:
"""Generator for likely subtag information.
Yields pairs (have, give) of 4-tuples; if what you have
Expand All @@ -50,8 +50,8 @@ def likelySubTags(self) -> Iterator[tuple[tuple[int, int, int, int],
skips = []
for got, use in self.root.likelySubTags():
try:
have: tuple[int, int, int, int] = self.__parseTags(got)
give: tuple[int, int, int, int] = self.__parseTags(use)
have: tuple[str, str, str, str] = self.__parseTags(got)
give: tuple[str, str, str, str] = self.__parseTags(use)
except Error as e:
if ((use.startswith(got) or got.startswith('und_'))
and e.message.startswith('Unknown ') and ' code ' in e.message):
Expand Down Expand Up @@ -206,7 +206,7 @@ def __wrapped(writer, prefix, tokens, wrap = textwrap.wrap) -> None:
subsequent_indent=' ', width=80)) + '\n')
del textwrap

def __parseTags(self, locale: str) -> tuple[int, int, int, int]:
def __parseTags(self, locale: str) -> tuple[str, str, str, str]:
tags: Iterator[str] = self.__splitLocale(locale)
language: str = next(tags)
script = territory = variant = ''
Expand Down
8 changes: 4 additions & 4 deletions util/locale_database/qlocalexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, filename: str) -> None:
scripts = tuple(self.__loadMap('script', script_map))
territories = tuple(self.__loadMap('territory', territory_map))

# as enum numeric values, tuple[tuple[int, int, int], tuple[int, int, int]]
# as enum members, tuple[tuple[str, str, str], tuple[str, str, str]]
self.__likely = tuple(self.__likelySubtagsMap())

# Mappings {ID: (enum name, code, en.xml name)}
Expand All @@ -74,7 +74,7 @@ def __init__(self, filename: str) -> None:

def loadLocaleMap(self, calendars: Iterable[str], grumble = lambda text: None):
kid: Callable[[minidom.Element, str], str] = self.__firstChildText
likely: dict[tuple[int, int, int], tuple[int, int, int]] = dict(self.__likely)
likely: dict[tuple[str, str, str], tuple[str, str, str]] = dict(self.__likely)

for elt in self.__eachEltInGroup(self.root, 'localeList', 'locale'):
locale: Locale = Locale.fromXmlData(lambda k: kid(elt, k), calendars)
Expand All @@ -91,7 +91,7 @@ def loadLocaleMap(self, calendars: Iterable[str], grumble = lambda text: None):
# http://www.unicode.org/reports/tr35/#Likely_Subtags
try:
try:
to: tuple[int, int, int] = likely[(locale.language, 'AnyScript',
to: tuple[str, str, str] = likely[(locale.language, 'AnyScript',
locale.territory)]
except KeyError:
to = likely[(locale.language, 'AnyScript', 'AnyTerritory')]
Expand Down Expand Up @@ -192,7 +192,7 @@ def __loadMap(self, category: str, enum: dict[int, tuple[str, str]]
yield key, enum[key][0], kid(element, 'code'), kid(element, 'name')

# Likely subtag management:
def __likelySubtagsMap(self) -> Iterator[tuple[tuple[int, int, int], tuple[int, int, int]]]:
def __likelySubtagsMap(self) -> Iterator[tuple[tuple[str, str, str], tuple[str, str, str]]]:
def triplet(element: minidom.Element,
keys: tuple[str, str, str]=('language', 'script', 'territory'),
kid = self.__firstChildText) -> tuple[str, str, str]:
Expand Down

0 comments on commit 34f6bf5

Please sign in to comment.