##// END OF EJS Templates
typing: add type annotations to mercurial/i18n.py...
Matt Harbison -
r47388:b9f40b74 default
parent child Browse files
Show More
@@ -19,6 +19,14 b' from . import ('
19 19 pycompat,
20 20 )
21 21
22 if pycompat.TYPE_CHECKING:
23 from typing import (
24 Callable,
25 List,
26 Optional,
27 )
28
29
22 30 # modelled after templater.templatepath:
23 31 if getattr(sys, 'frozen', None) is not None:
24 32 module = pycompat.sysexecutable
@@ -40,7 +48,10 b' if ('
40 48 try:
41 49 import ctypes
42 50
51 # pytype: disable=module-attr
43 52 langid = ctypes.windll.kernel32.GetUserDefaultUILanguage()
53 # pytype: enable=module-attr
54
44 55 _languages = [locale.windows_locale[langid]]
45 56 except (ImportError, AttributeError, KeyError):
46 57 # ctypes not found or unknown langid
@@ -51,7 +62,7 b' datapath = pycompat.fsdecode(resourceuti'
51 62 localedir = os.path.join(datapath, 'locale')
52 63 t = gettextmod.translation('hg', localedir, _languages, fallback=True)
53 64 try:
54 _ugettext = t.ugettext
65 _ugettext = t.ugettext # pytype: disable=attribute-error
55 66 except AttributeError:
56 67 _ugettext = t.gettext
57 68
@@ -60,6 +71,7 b' except AttributeError:'
60 71
61 72
62 73 def gettext(message):
74 # type: (Optional[bytes]) -> Optional[bytes]
63 75 """Translate message.
64 76
65 77 The message is looked up in the catalog to get a Unicode string,
@@ -77,7 +89,7 b' def gettext(message):'
77 89 if message not in cache:
78 90 if type(message) is pycompat.unicode:
79 91 # goofy unicode docstrings in test
80 paragraphs = message.split(u'\n\n')
92 paragraphs = message.split(u'\n\n') # type: List[pycompat.unicode]
81 93 else:
82 94 # should be ascii, but we have unicode docstrings in test, which
83 95 # are converted to utf-8 bytes on Python 3.
@@ -110,6 +122,6 b' def _plain():'
110 122
111 123
112 124 if _plain():
113 _ = lambda message: message
125 _ = lambda message: message # type: Callable[[bytes], bytes]
114 126 else:
115 127 _ = gettext
General Comments 0
You need to be logged in to leave comments. Login now