Skip to content

Commit 664c4e2

Browse files
committed
index directive and role emit deprecation warnings for python index-types
1 parent 1fc4e8c commit 664c4e2

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Features added
2727
old stub file
2828
* #5923: autodoc: ``:inherited-members:`` option takes a name of anchestor class
2929
not to document inherited members of the class and uppers
30+
* :rst:dir:`index` and :rst:role:`index` emit deprecation warnings for python
31+
specific index-types
3032

3133
Bugs fixed
3234
----------

doc/usage/restructuredtext/directives.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,8 @@ mainly contained in information units, such as the language reference.
852852
creates the entries ``module; hashlib`` and ``hashlib; module``. (These
853853
are Python-specific and therefore deprecated.)
854854

855+
.. deprecated:: 1.0
856+
855857
You can mark up "main" index entries by prefixing them with an exclamation
856858
mark. The references to "main" entries are emphasized in the generated
857859
index. For example, if two pages contain ::

sphinx/directives/other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def run(self) -> List[Node]:
202202
indexnode['inline'] = False
203203
self.set_source_info(indexnode)
204204
for entry in arguments:
205-
indexnode['entries'].extend(process_index_entry(entry, targetid))
205+
indexnode['entries'].extend(process_index_entry(entry, targetid, indexnode))
206206
return [indexnode, targetnode]
207207

208208

sphinx/roles.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ def index_role(typ: str, rawtext: str, text: str, lineno: int, inliner: Inliner,
554554
target = utils.unescape(target)
555555
# if an explicit target is given, we can process it as a full entry
556556
if has_explicit_title:
557-
entries = process_index_entry(target, targetid)
557+
source, line = inliner.reporter.get_source_and_line(lineno) # type: ignore
558+
entries = process_index_entry(target, targetid, (source, line))
558559
# otherwise we just create a "single" entry
559560
else:
560561
# but allow giving main entry
@@ -573,24 +574,25 @@ def index_role(typ: str, rawtext: str, text: str, lineno: int, inliner: Inliner,
573574

574575
class Index(ReferenceRole):
575576
def run(self) -> Tuple[List[Node], List[system_message]]:
577+
index = addnodes.index(entries=[])
578+
self.set_source_info(index)
579+
576580
target_id = 'index-%s' % self.env.new_serialno('index')
577581
if self.has_explicit_title:
578582
# if an explicit target is given, process it as a full entry
579583
title = self.title
580-
entries = process_index_entry(self.target, target_id)
584+
index['entries'].extend(process_index_entry(self.target, target_id, index))
581585
else:
582586
# otherwise we just create a single entry
583587
if self.target.startswith('!'):
584588
title = self.title[1:]
585-
entries = [('single', self.target[1:], target_id, 'main', None)]
589+
index['entries'].append(('single', self.target[1:], target_id, 'main', None))
586590
else:
587591
title = self.title
588-
entries = [('single', self.target, target_id, '', None)]
592+
index['entries'].append(('single', self.target, target_id, '', None))
589593

590-
index = addnodes.index(entries=entries)
591594
target = nodes.target('', '', ids=[target_id])
592595
text = nodes.Text(title, title)
593-
self.set_source_info(index)
594596
return [index, target, text], []
595597

596598

sphinx/util/nodes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ def split_explicit_title(text: str) -> Tuple[bool, str, str]:
363363
]
364364

365365

366-
def process_index_entry(entry: str, targetid: str) -> List[Tuple[str, str, str, str, str]]:
366+
def process_index_entry(entry: str, targetid: str, location: Any = None
367+
) -> List[Tuple[str, str, str, str, str]]:
367368
from sphinx.domains.python import pairindextypes
368369

369370
indexentries = [] # type: List[Tuple[str, str, str, str, str]]
@@ -375,6 +376,11 @@ def process_index_entry(entry: str, targetid: str) -> List[Tuple[str, str, str,
375376
entry = entry[1:].lstrip()
376377
for type in pairindextypes:
377378
if entry.startswith(type + ':'):
379+
logger.warning(__('indextype "%s" is deprecated. '
380+
'Please use "pair: %s; %s" instead.'),
381+
type, type, entry[len(type) + 1:].strip(),
382+
location=location) # RemovedInSphinx50Warning
383+
378384
value = entry[len(type) + 1:].strip()
379385
value = pairindextypes[type] + '; ' + value
380386
indexentries.append(('pair', value, targetid, main, None))

tests/roots/test-root/markup.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ Index markup
371371
pair: entry; pair
372372
double: entry; double
373373
triple: index; entry; triple
374-
keyword: with
375374
see: from; to
376375
seealso: fromalso; toalso
377376

0 commit comments

Comments
 (0)