Skip to content

Commit 32a6161

Browse files
committed
Restore annotations in sphinx.locale to objects
1 parent a7fab7a commit 32a6161

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

sphinx/locale/__init__.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
import locale
44
from gettext import NullTranslations, translation
55
from os import path
6-
7-
if False:
8-
# NoQA
9-
from collections.abc import Callable, Iterable
10-
from typing import Any, Dict, List, Optional, Tuple, Union
6+
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
117

128

139
class _TranslationProxy:
@@ -20,32 +16,32 @@ class _TranslationProxy:
2016
"""
2117
__slots__ = ('_func', '_args')
2218

23-
def __new__(cls, func: 'Callable', *args: str) -> '_TranslationProxy':
19+
def __new__(cls, func: Callable, *args: str) -> '_TranslationProxy':
2420
if not args:
2521
# not called with "function" and "arguments", but a plain string
2622
return str(func) # type: ignore[return-value]
2723
return object.__new__(cls)
2824

29-
def __getnewargs__(self) -> 'Tuple[str]':
25+
def __getnewargs__(self) -> Tuple[str]:
3026
return (self._func,) + self._args # type: ignore
3127

32-
def __init__(self, func: 'Callable', *args: str) -> None:
28+
def __init__(self, func: Callable, *args: str) -> None:
3329
self._func = func
3430
self._args = args
3531

3632
def __str__(self) -> str:
3733
return str(self._func(*self._args))
3834

39-
def __dir__(self) -> 'List[str]':
35+
def __dir__(self) -> List[str]:
4036
return dir(str)
4137

42-
def __getattr__(self, name: str) -> 'Any':
38+
def __getattr__(self, name: str) -> Any:
4339
return getattr(self.__str__(), name)
4440

45-
def __getstate__(self) -> 'Tuple[Callable, Tuple[str, ...]]':
41+
def __getstate__(self) -> Tuple[Callable, Tuple[str, ...]]:
4642
return self._func, self._args
4743

48-
def __setstate__(self, tup: 'Tuple[Callable, Tuple[str]]') -> None:
44+
def __setstate__(self, tup: Tuple[Callable, Tuple[str]]) -> None:
4945
self._func, self._args = tup
5046

5147
def __copy__(self) -> '_TranslationProxy':
@@ -69,10 +65,10 @@ def __mod__(self, other: str) -> str:
6965
def __rmod__(self, other: str) -> str:
7066
return other % self.__str__()
7167

72-
def __mul__(self, other: 'Any') -> str:
68+
def __mul__(self, other: Any) -> str:
7369
return self.__str__() * other
7470

75-
def __rmul__(self, other: 'Any') -> str:
71+
def __rmul__(self, other: Any) -> str:
7672
return other * self.__str__()
7773

7874
def __hash__(self):
@@ -94,15 +90,15 @@ def __getitem__(self, index):
9490
return self.__str__()[index]
9591

9692

97-
translators: 'Dict[Tuple[str, str], NullTranslations]' = {}
93+
translators: Dict[Tuple[str, str], NullTranslations] = {}
9894

9995

10096
def init(
101-
locale_dirs: 'List[Optional[str]]',
102-
language: 'Optional[str]',
97+
locale_dirs: List[Optional[str]],
98+
language: Optional[str],
10399
catalog: str = 'sphinx',
104100
namespace: str = 'general',
105-
) -> 'Tuple[NullTranslations, bool]':
101+
) -> Tuple[NullTranslations, bool]:
106102
"""Look for message catalogs in `locale_dirs` and *ensure* that there is at
107103
least a NullTranslations catalog set in `translators`. If called multiple
108104
times or if several ``.mo`` files are found, their contents are merged
@@ -118,7 +114,7 @@ def init(
118114

119115
if language and '_' in language:
120116
# for language having country code (like "de_AT")
121-
languages: 'Optional[List[str]]' = [language, language.split('_')[0]]
117+
languages: Optional[List[str]] = [language, language.split('_')[0]]
122118
elif language:
123119
languages = [language]
124120
else:
@@ -143,7 +139,7 @@ def init(
143139
return translator, has_translation
144140

145141

146-
def setlocale(category: int, value: 'Union[str, Iterable[str], None]' = None) -> None:
142+
def setlocale(category: int, value: Union[str, Iterable[str], None] = None) -> None:
147143
"""Update locale settings.
148144
149145
This does not throw any exception even if update fails.
@@ -166,7 +162,7 @@ def setlocale(category: int, value: 'Union[str, Iterable[str], None]' = None) ->
166162
def init_console(
167163
locale_dir: str = path.abspath(path.dirname(__file__)), # NoQA: B008
168164
catalog: str = 'sphinx',
169-
) -> 'Tuple[NullTranslations, bool]':
165+
) -> Tuple[NullTranslations, bool]:
170166
"""Initialize locale for console.
171167
172168
.. versionadded:: 1.8
@@ -197,7 +193,7 @@ def _lazy_translate(catalog: str, namespace: str, message: str) -> str:
197193
return translator.gettext(message)
198194

199195

200-
def get_translation(catalog: str, namespace: str = 'general') -> 'Callable[[str], str]':
196+
def get_translation(catalog: str, namespace: str = 'general') -> Callable[[str], str]:
201197
"""Get a translation function based on the *catalog* and *namespace*.
202198
203199
The extension can use this API to translate the messages on the
@@ -222,7 +218,7 @@ def setup(app):
222218
223219
.. versionadded:: 1.8
224220
"""
225-
def gettext(message: str, *args: 'Any') -> str:
221+
def gettext(message: str, *args: Any) -> str:
226222
if not is_translator_registered(catalog, namespace):
227223
# not initialized yet
228224
return _TranslationProxy(_lazy_translate, catalog, namespace, message) # type: ignore # NOQA
@@ -260,7 +256,7 @@ def gettext(message: str, *args: 'Any') -> str:
260256
}
261257

262258
# Moved to sphinx.directives.other (will be overridden later)
263-
versionlabels: 'Dict[str, str]' = {}
259+
versionlabels: Dict[str, str] = {}
264260

265261
# Moved to sphinx.domains.python (will be overridden later)
266-
pairindextypes: 'Dict[str, str]' = {}
262+
pairindextypes: Dict[str, str] = {}

0 commit comments

Comments
 (0)