Correct some type-annotations in util/locale_database/
Amends commit 3b541daff71b6efa9592f6acc41ea0e61ece34f3 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 bd5bb70b7c980d737d03db7a9d00b864fa144de0) 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 <mate.barany@qt.io>
This commit is contained in:
parent
948599e7b7
commit
34f6bf5b7c
@ -38,8 +38,8 @@ class CldrReader (object):
|
||||
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
|
||||
@ -50,8 +50,8 @@ class CldrReader (object):
|
||||
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):
|
||||
@ -206,7 +206,7 @@ class CldrReader (object):
|
||||
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 = ''
|
||||
|
@ -56,7 +56,7 @@ class QLocaleXmlReader (object):
|
||||
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)}
|
||||
@ -74,7 +74,7 @@ class QLocaleXmlReader (object):
|
||||
|
||||
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)
|
||||
@ -91,7 +91,7 @@ class QLocaleXmlReader (object):
|
||||
# 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')]
|
||||
@ -192,7 +192,7 @@ class QLocaleXmlReader (object):
|
||||
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]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user