diff options
author | Adam Turner <9087854+AA-Turner@users.noreply.github.com> | 2023-05-09 22:57:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 22:57:39 +0100 |
commit | 706f5f9cc83f1d62829bb18ad40bfa5e784e202c (patch) | |
tree | 1507067d704327404f565136631771b34a447a7e /sphinx | |
parent | db546189ce1d2a345f4399367ced6ecdd538be5d (diff) | |
download | sphinx-git-706f5f9cc83f1d62829bb18ad40bfa5e784e202c.tar.gz |
Warn on deprecated Python-specific index types (#11412)
Diffstat (limited to 'sphinx')
-rw-r--r-- | sphinx/builders/gettext.py | 5 | ||||
-rw-r--r-- | sphinx/domains/python.py | 18 | ||||
-rw-r--r-- | sphinx/locale/__init__.py | 6 | ||||
-rw-r--r-- | sphinx/util/nodes.py | 24 |
4 files changed, 23 insertions, 30 deletions
diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 4d460109b..697b75e40 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -16,7 +16,6 @@ from docutils.nodes import Element from sphinx import addnodes, package_dir from sphinx.application import Sphinx from sphinx.builders import Builder -from sphinx.domains.python import pairindextypes from sphinx.errors import ThemeError from sphinx.locale import __ from sphinx.util import logging, split_index_msg @@ -159,10 +158,6 @@ class I18nBuilder(Builder): for node, entries in traverse_translatable_index(doctree): for typ, msg, _tid, _main, _key in entries: for m in split_index_msg(typ, msg): - if typ == 'pair' and m in pairindextypes.values(): - # avoid built-in translated message was incorporated - # in 'sphinx.util.nodes.process_index_entry' - continue catalog.add(m, node) diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index c461cc311..eef78aa80 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -50,13 +50,13 @@ py_sig_re = re.compile( pairindextypes = { - 'module': _('module'), - 'keyword': _('keyword'), - 'operator': _('operator'), - 'object': _('object'), - 'exception': _('exception'), - 'statement': _('statement'), - 'builtin': _('built-in function'), + 'module': 'module', + 'keyword': 'keyword', + 'operator': 'operator', + 'object': 'object', + 'exception': 'exception', + 'statement': 'statement', + 'builtin': 'built-in function', } @@ -729,7 +729,7 @@ class PyFunction(PyObject): text = _('%s() (in module %s)') % (name, modname) self.indexnode['entries'].append(('single', text, node_id, '', None)) else: - text = f'{pairindextypes["builtin"]}; {name}()' + text = f'built-in function; {name}()' self.indexnode['entries'].append(('pair', text, node_id, '', None)) def get_index_text(self, modname: str, name_cls: tuple[str, str]) -> str | None: @@ -1058,7 +1058,7 @@ class PyModule(SphinxDirective): # the platform and synopsis aren't printed; in fact, they are only # used in the modindex currently ret.append(target) - indextext = f'{pairindextypes["module"]}; {modname}' + indextext = f'module; {modname}' inode = addnodes.index(entries=[('pair', indextext, node_id, '', None)]) ret.append(inode) ret.extend(content_node.children) diff --git a/sphinx/locale/__init__.py b/sphinx/locale/__init__.py index c92640576..8ab90d191 100644 --- a/sphinx/locale/__init__.py +++ b/sphinx/locale/__init__.py @@ -223,9 +223,3 @@ admonitionlabels = { 'tip': _('Tip'), 'warning': _('Warning'), } - -# Moved to sphinx.directives.other (will be overridden later) -versionlabels: dict[str, str] = {} - -# Moved to sphinx.domains.python (will be overridden later) -pairindextypes: dict[str, str] = {} diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 1b43bd72e..3dfdd4f26 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -365,19 +365,23 @@ def process_index_entry(entry: str, targetid: str, if entry.startswith('!'): main = 'main' entry = entry[1:].lstrip() - for type in pairindextypes: - if entry.startswith(type + ':'): - value = entry[len(type) + 1:].strip() - value = pairindextypes[type] + '; ' + value + for index_type in pairindextypes: + if entry.startswith(f'{index_type}:'): + value = entry[len(index_type) + 1:].strip() + value = f'{pairindextypes[index_type]}; {value}' + # xref RemovedInSphinx90Warning + logger.warning(__('%r is deprecated for index entries (from entry %r). ' + "Use 'pair: %s' instead."), + index_type, entry, value, type='index') indexentries.append(('pair', value, targetid, main, None)) break else: - for type in indextypes: - if entry.startswith(type + ':'): - value = entry[len(type) + 1:].strip() - if type == 'double': - type = 'pair' - indexentries.append((type, value, targetid, main, None)) + for index_type in indextypes: + if entry.startswith(f'{index_type}:'): + value = entry[len(index_type) + 1:].strip() + if index_type == 'double': + index_type = 'pair' + indexentries.append((index_type, value, targetid, main, None)) break # shorthand notation for single entries else: |