Skip to content

Commit cfd3645

Browse files
authored
intersphinx: Don't warn about pure-duplicate ambiguous definitions when loading inventory entries (#12586)
1 parent afaddd3 commit cfd3645

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

sphinx/util/inventory.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def load_v2(
126126
invdata: Inventory = {}
127127
projname = stream.readline().rstrip()[11:]
128128
version = stream.readline().rstrip()[11:]
129-
potential_ambiguities = set()
129+
# definition -> priority, location, display name
130+
potential_ambiguities: dict[str, tuple[str, str, str]] = {}
130131
actual_ambiguities = set()
131132
line = stream.readline()
132133
if 'zlib' not in line:
@@ -155,10 +156,16 @@ def load_v2(
155156
# * 'term': https://github.com/sphinx-doc/sphinx/issues/9291
156157
# * 'label': https://github.com/sphinx-doc/sphinx/issues/12008
157158
definition = f"{type}:{name}"
158-
if definition.lower() in potential_ambiguities:
159-
actual_ambiguities.add(definition)
159+
content = prio, location, dispname
160+
lowercase_definition = definition.lower()
161+
if lowercase_definition in potential_ambiguities:
162+
if potential_ambiguities[lowercase_definition] != content:
163+
actual_ambiguities.add(definition)
164+
else:
165+
logger.debug(__("inventory <%s> contains duplicate definitions of %s"),
166+
uri, definition, type='intersphinx', subtype='external')
160167
else:
161-
potential_ambiguities.add(definition.lower())
168+
potential_ambiguities[lowercase_definition] = content
162169
if location.endswith('$'):
163170
location = location[:-1] + name
164171
location = join(uri, location)

tests/test_util/intersphinx_data.py

+2
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@
5959
''' + zlib.compress(b'''\
6060
a term std:term -1 glossary.html#term-a-term -
6161
A term std:term -1 glossary.html#term-a-term -
62+
b term std:term -1 document.html#id5 -
63+
B term std:term -1 document.html#B -
6264
''')

tests/test_util/test_util_inventory.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def test_ambiguous_definition_warning(warning):
5353
f = BytesIO(INVENTORY_V2_AMBIGUOUS_TERMS)
5454
InventoryFile.load(f, '/util', posixpath.join)
5555

56-
assert 'contains multiple definitions for std:term:a' in warning.getvalue().lower()
56+
assert 'contains multiple definitions for std:term:a' not in warning.getvalue().lower()
57+
assert 'contains multiple definitions for std:term:b' in warning.getvalue().lower()
5758

5859

5960
def _write_appconfig(dir, language, prefix=None):

0 commit comments

Comments
 (0)