mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix mypy violations
This commit is contained in:
parent
bc31485b10
commit
645ad75523
@ -273,7 +273,7 @@ class Sphinx(object):
|
||||
locale_dirs = [None, path.join(package_dir, 'locale')] + user_locale_dirs # type: ignore # NOQA
|
||||
else:
|
||||
locale_dirs = []
|
||||
self.translator, has_translation = locale.init(locale_dirs, self.config.language)
|
||||
self.translator, has_translation = locale.init(locale_dirs, self.config.language) # type: ignore # NOQA
|
||||
if self.config.language is not None:
|
||||
if has_translation or self.config.language == 'en':
|
||||
# "en" never needs to be translated
|
||||
|
@ -446,7 +446,7 @@ class StandaloneHTMLBuilder(Builder):
|
||||
# typically doesn't include the time of day
|
||||
lufmt = self.config.html_last_updated_fmt
|
||||
if lufmt is not None:
|
||||
self.last_updated = format_date(lufmt or _('%b %d, %Y'), # type: ignore
|
||||
self.last_updated = format_date(lufmt or _('%b %d, %Y'),
|
||||
language=self.config.language)
|
||||
else:
|
||||
self.last_updated = None
|
||||
|
@ -205,7 +205,7 @@ translators = defaultdict(NullTranslations) # type: Dict[Tuple[unicode, unicode
|
||||
|
||||
|
||||
def init(locale_dirs, language, catalog='sphinx', namespace='general'):
|
||||
# type: (List, unicode, unicode) -> Tuple[Any, bool]
|
||||
# type: (List[unicode], unicode, unicode, unicode) -> Tuple[NullTranslations, bool]
|
||||
"""Look for message catalogs in `locale_dirs` and *ensure* that there is at
|
||||
least a NullTranslations catalog set in `translators`. If called multiple
|
||||
times or if several ``.mo`` files are found, their contents are merged
|
||||
@ -229,7 +229,7 @@ def init(locale_dirs, language, catalog='sphinx', namespace='general'):
|
||||
for dir_ in locale_dirs:
|
||||
try:
|
||||
trans = gettext.translation(catalog, localedir=dir_, # type: ignore
|
||||
languages=languages) # type: ignore
|
||||
languages=languages)
|
||||
if translator is None:
|
||||
translator = trans
|
||||
else:
|
||||
@ -243,12 +243,12 @@ def init(locale_dirs, language, catalog='sphinx', namespace='general'):
|
||||
has_translation = False
|
||||
translators[(namespace, catalog)] = translator
|
||||
if hasattr(translator, 'ugettext'):
|
||||
translator.gettext = translator.ugettext
|
||||
translator.gettext = translator.ugettext # type: ignore
|
||||
return translator, has_translation
|
||||
|
||||
|
||||
def init_console(locale_dir, catalog):
|
||||
# type: (unicode, unicode) -> None
|
||||
# type: (unicode, unicode) -> Tuple[NullTranslations, bool]
|
||||
"""Initialize locale for console.
|
||||
|
||||
.. versionadded:: 1.8
|
||||
@ -273,11 +273,10 @@ def _lazy_translate(catalog, namespace, message):
|
||||
not bound yet at that time.
|
||||
"""
|
||||
translator = get_translator(catalog, namespace)
|
||||
return translator.gettext(message)
|
||||
return translator.gettext(message) # type: ignore
|
||||
|
||||
|
||||
def get_translation(catalog, namespace='general'):
|
||||
# type: (unicode, unicode) -> Callable[[unicode, *Any], unicode]
|
||||
"""Get a translation function based on the *catalog* and *namespace*.
|
||||
|
||||
The extension can use this API to translate the messages on the
|
||||
@ -305,13 +304,13 @@ def get_translation(catalog, namespace='general'):
|
||||
# type: (unicode, *Any) -> unicode
|
||||
if not is_translator_registered(catalog, namespace):
|
||||
# not initialized yet
|
||||
return _TranslationProxy(_lazy_translate, catalog, namespace, message)
|
||||
return _TranslationProxy(_lazy_translate, catalog, namespace, message) # type: ignore # NOQA
|
||||
else:
|
||||
translator = get_translator(catalog, namespace)
|
||||
if len(args) <= 1:
|
||||
return translator.gettext(message)
|
||||
return translator.gettext(message) # type: ignore
|
||||
else: # support pluralization
|
||||
return translator.ngettext(message, args[0], args[1])
|
||||
return translator.ngettext(message, args[0], args[1]) # type: ignore
|
||||
|
||||
return gettext
|
||||
|
||||
|
@ -125,7 +125,7 @@ class DefaultSubstitutions(SphinxTransform):
|
||||
text = self.config[refname]
|
||||
if refname == 'today' and not text:
|
||||
# special handling: can also specify a strftime format
|
||||
text = format_date(self.config.today_fmt or _('%b %d, %Y'), # type: ignore
|
||||
text = format_date(self.config.today_fmt or _('%b %d, %Y'),
|
||||
language=self.config.language)
|
||||
ref.replace_self(nodes.Text(text, text))
|
||||
|
||||
|
@ -86,6 +86,8 @@ class Locale(SphinxTransform):
|
||||
def apply(self):
|
||||
# type: () -> None
|
||||
settings, source = self.document.settings, self.document['source']
|
||||
msgstr = u''
|
||||
|
||||
# XXX check if this is reliable
|
||||
assert source.startswith(self.env.srcdir)
|
||||
docname = path.splitext(relative_path(path.join(self.env.srcdir, 'dummy'),
|
||||
@ -102,7 +104,7 @@ class Locale(SphinxTransform):
|
||||
|
||||
# phase1: replace reference ids with translated names
|
||||
for node, msg in extract_messages(self.document):
|
||||
msgstr = catalog.gettext(msg)
|
||||
msgstr = catalog.gettext(msg) # type: ignore
|
||||
# XXX add marker to untranslated parts
|
||||
if not msgstr or msgstr == msg or not msgstr.strip():
|
||||
# as-of-yet untranslated
|
||||
@ -219,7 +221,7 @@ class Locale(SphinxTransform):
|
||||
if node.get('translated', False): # to avoid double translation
|
||||
continue # skip if the node is already translated by phase1
|
||||
|
||||
msgstr = catalog.gettext(msg)
|
||||
msgstr = catalog.gettext(msg) # type: ignore
|
||||
# XXX add marker to untranslated parts
|
||||
if not msgstr or msgstr == msg: # as-of-yet untranslated
|
||||
continue
|
||||
@ -438,7 +440,7 @@ class Locale(SphinxTransform):
|
||||
msg_parts = split_index_msg(type, msg)
|
||||
msgstr_parts = []
|
||||
for part in msg_parts:
|
||||
msgstr = catalog.gettext(part)
|
||||
msgstr = catalog.gettext(part) # type: ignore
|
||||
if not msgstr:
|
||||
msgstr = part
|
||||
msgstr_parts.append(msgstr)
|
||||
|
@ -580,7 +580,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if builder.config.today:
|
||||
self.elements['date'] = builder.config.today
|
||||
else:
|
||||
self.elements['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'), # type: ignore # NOQA
|
||||
self.elements['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
|
||||
language=builder.config.language)
|
||||
|
||||
if builder.config.numfig:
|
||||
|
@ -108,7 +108,7 @@ class ManualPageTranslator(BaseTranslator):
|
||||
if builder.config.today:
|
||||
self._docinfo['date'] = builder.config.today
|
||||
else:
|
||||
self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'), # type: ignore # NOQA
|
||||
self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
|
||||
language=builder.config.language)
|
||||
self._docinfo['copyright'] = builder.config.copyright
|
||||
self._docinfo['version'] = builder.config.version
|
||||
|
@ -237,7 +237,7 @@ class TexinfoTranslator(nodes.NodeVisitor):
|
||||
'project': self.escape(self.builder.config.project),
|
||||
'copyright': self.escape(self.builder.config.copyright),
|
||||
'date': self.escape(self.builder.config.today or
|
||||
format_date(self.builder.config.today_fmt or _('%b %d, %Y'), # type: ignore # NOQA
|
||||
format_date(self.builder.config.today_fmt or _('%b %d, %Y'),
|
||||
language=self.builder.config.language))
|
||||
})
|
||||
# title
|
||||
|
Loading…
Reference in New Issue
Block a user