Skip to content

Commit 655d1c7

Browse files
authored
intersphinx: Reduce log message severity when an ambiguous target resolves to a duplicate (#12587)
1 parent ed7a980 commit 655d1c7

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Bugs fixed
3232
so that it now runs after the docutils ``Footnotes`` resolution transform.
3333
Patch by Chris Sewell.
3434

35+
* #12587: Do not warn when potential ambiguity detected during Intersphinx
36+
resolution occurs due to duplicate targets that differ case-insensitively.
37+
Patch by James Addison.
38+
3539
Testing
3640
-------
3741

sphinx/ext/intersphinx/_resolve.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,16 @@ def _resolve_reference_in_domain_by_target(
8282
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
8383
inventory[objtype].keys()))
8484
if len(insensitive_matches) > 1:
85+
data_items = {inventory[objtype][match] for match in insensitive_matches}
8586
inv_descriptor = inv_name or 'main_inventory'
86-
LOGGER.warning(__("inventory '%s': multiple matches found for %s:%s"),
87-
inv_descriptor, objtype, target,
88-
type='intersphinx', subtype='external', location=node)
87+
if len(data_items) == 1: # these are duplicates; relatively innocuous
88+
LOGGER.debug(__("inventory '%s': duplicate matches found for %s:%s"),
89+
inv_descriptor, objtype, target,
90+
type='intersphinx', subtype='external', location=node)
91+
else:
92+
LOGGER.warning(__("inventory '%s': multiple matches found for %s:%s"),
93+
inv_descriptor, objtype, target,
94+
type='intersphinx', subtype='external', location=node)
8995
if insensitive_matches:
9096
data = inventory[objtype][insensitive_matches[0]]
9197
else:

tests/test_extensions/test_ext_intersphinx.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,14 @@ def test_missing_reference_stddomain(tmp_path, app):
313313
assert rn.astext() == 'The Julia Domain'
314314

315315

316-
def test_ambiguous_reference_warning(tmp_path, app):
316+
@pytest.mark.parametrize(
317+
('term', 'expected_ambiguity'),
318+
[
319+
('A TERM', False),
320+
('B TERM', True),
321+
],
322+
)
323+
def test_ambiguous_reference_handling(term, expected_ambiguity, tmp_path, app, warning):
317324
inv_file = tmp_path / 'inventory'
318325
inv_file.write_bytes(INVENTORY_V2_AMBIGUOUS_TERMS)
319326
set_config(
@@ -328,10 +335,11 @@ def test_ambiguous_reference_warning(tmp_path, app):
328335
load_mappings(app)
329336

330337
# term reference (case insensitive)
331-
node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM')
338+
node, contnode = fake_node('std', 'term', term, term)
332339
missing_reference(app, app.env, node, contnode)
333340

334-
assert 'multiple matches found for std:term:A TERM' in app.warning.getvalue()
341+
ambiguity = f'multiple matches found for std:term:{term}' in warning.getvalue()
342+
assert ambiguity is expected_ambiguity
335343

336344

337345
@pytest.mark.sphinx('html', testroot='ext-intersphinx-cppdomain')

0 commit comments

Comments
 (0)