##// 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 pycompat,
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 # modelled after templater.templatepath:
30 # modelled after templater.templatepath:
23 if getattr(sys, 'frozen', None) is not None:
31 if getattr(sys, 'frozen', None) is not None:
24 module = pycompat.sysexecutable
32 module = pycompat.sysexecutable
@@ -40,7 +48,10 b' if ('
40 try:
48 try:
41 import ctypes
49 import ctypes
42
50
51 # pytype: disable=module-attr
43 langid = ctypes.windll.kernel32.GetUserDefaultUILanguage()
52 langid = ctypes.windll.kernel32.GetUserDefaultUILanguage()
53 # pytype: enable=module-attr
54
44 _languages = [locale.windows_locale[langid]]
55 _languages = [locale.windows_locale[langid]]
45 except (ImportError, AttributeError, KeyError):
56 except (ImportError, AttributeError, KeyError):
46 # ctypes not found or unknown langid
57 # ctypes not found or unknown langid
@@ -51,7 +62,7 b' datapath = pycompat.fsdecode(resourceuti'
51 localedir = os.path.join(datapath, 'locale')
62 localedir = os.path.join(datapath, 'locale')
52 t = gettextmod.translation('hg', localedir, _languages, fallback=True)
63 t = gettextmod.translation('hg', localedir, _languages, fallback=True)
53 try:
64 try:
54 _ugettext = t.ugettext
65 _ugettext = t.ugettext # pytype: disable=attribute-error
55 except AttributeError:
66 except AttributeError:
56 _ugettext = t.gettext
67 _ugettext = t.gettext
57
68
@@ -60,6 +71,7 b' except AttributeError:'
60
71
61
72
62 def gettext(message):
73 def gettext(message):
74 # type: (Optional[bytes]) -> Optional[bytes]
63 """Translate message.
75 """Translate message.
64
76
65 The message is looked up in the catalog to get a Unicode string,
77 The message is looked up in the catalog to get a Unicode string,
@@ -77,7 +89,7 b' def gettext(message):'
77 if message not in cache:
89 if message not in cache:
78 if type(message) is pycompat.unicode:
90 if type(message) is pycompat.unicode:
79 # goofy unicode docstrings in test
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 else:
93 else:
82 # should be ascii, but we have unicode docstrings in test, which
94 # should be ascii, but we have unicode docstrings in test, which
83 # are converted to utf-8 bytes on Python 3.
95 # are converted to utf-8 bytes on Python 3.
@@ -110,6 +122,6 b' def _plain():'
110
122
111
123
112 if _plain():
124 if _plain():
113 _ = lambda message: message
125 _ = lambda message: message # type: Callable[[bytes], bytes]
114 else:
126 else:
115 _ = gettext
127 _ = gettext
General Comments 0
You need to be logged in to leave comments. Login now