Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions sphinx/util/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def load_v2(
invdata: Inventory = {}
projname = stream.readline().rstrip()[11:]
version = stream.readline().rstrip()[11:]
potential_ambiguities = set()
# definition -> priority, location, display name
potential_ambiguities: dict[str, tuple[str, str, str]] = {}
actual_ambiguities = set()
line = stream.readline()
if 'zlib' not in line:
Expand Down Expand Up @@ -155,10 +156,16 @@ def load_v2(
# * 'term': https://github.com/sphinx-doc/sphinx/issues/9291
# * 'label': https://github.com/sphinx-doc/sphinx/issues/12008
definition = f"{type}:{name}"
if definition.lower() in potential_ambiguities:
actual_ambiguities.add(definition)
content = prio, location, dispname
lowercase_definition = definition.lower()
if lowercase_definition in potential_ambiguities:
if potential_ambiguities[lowercase_definition] != content:
actual_ambiguities.add(definition)
else:
logger.debug(__("inventory <%s> contains duplicate definitions of %s"),
uri, definition, type='intersphinx', subtype='external')
else:
potential_ambiguities.add(definition.lower())
potential_ambiguities[lowercase_definition] = content
if location.endswith('$'):
location = location[:-1] + name
location = join(uri, location)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_util/intersphinx_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@
''' + zlib.compress(b'''\
a term std:term -1 glossary.html#term-a-term -
A term std:term -1 glossary.html#term-a-term -
b term std:term -1 document.html#id5 -
B term std:term -1 document.html#B -
''')
3 changes: 2 additions & 1 deletion tests/test_util/test_util_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def test_ambiguous_definition_warning(warning):
f = BytesIO(INVENTORY_V2_AMBIGUOUS_TERMS)
InventoryFile.load(f, '/util', posixpath.join)

assert 'contains multiple definitions for std:term:a' in warning.getvalue().lower()
assert 'contains multiple definitions for std:term:a' not in warning.getvalue().lower()
assert 'contains multiple definitions for std:term:b' in warning.getvalue().lower()


def _write_appconfig(dir, language, prefix=None):
Expand Down