Skip to content

Commit

Permalink
intersphinx: Reduce log message severity when an ambiguous target res…
Browse files Browse the repository at this point in the history
…olves to a duplicate (#12587)
  • Loading branch information
jayaddison authored Aug 11, 2024
1 parent ed7a980 commit 655d1c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Bugs fixed
so that it now runs after the docutils ``Footnotes`` resolution transform.
Patch by Chris Sewell.

* #12587: Do not warn when potential ambiguity detected during Intersphinx
resolution occurs due to duplicate targets that differ case-insensitively.
Patch by James Addison.

Testing
-------

Expand Down
12 changes: 9 additions & 3 deletions sphinx/ext/intersphinx/_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ def _resolve_reference_in_domain_by_target(
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
inventory[objtype].keys()))
if len(insensitive_matches) > 1:
data_items = {inventory[objtype][match] for match in insensitive_matches}
inv_descriptor = inv_name or 'main_inventory'
LOGGER.warning(__("inventory '%s': multiple matches found for %s:%s"),
inv_descriptor, objtype, target,
type='intersphinx', subtype='external', location=node)
if len(data_items) == 1: # these are duplicates; relatively innocuous
LOGGER.debug(__("inventory '%s': duplicate matches found for %s:%s"),
inv_descriptor, objtype, target,
type='intersphinx', subtype='external', location=node)
else:
LOGGER.warning(__("inventory '%s': multiple matches found for %s:%s"),
inv_descriptor, objtype, target,
type='intersphinx', subtype='external', location=node)
if insensitive_matches:
data = inventory[objtype][insensitive_matches[0]]
else:
Expand Down
14 changes: 11 additions & 3 deletions tests/test_extensions/test_ext_intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,14 @@ def test_missing_reference_stddomain(tmp_path, app):
assert rn.astext() == 'The Julia Domain'


def test_ambiguous_reference_warning(tmp_path, app):
@pytest.mark.parametrize(
('term', 'expected_ambiguity'),
[
('A TERM', False),
('B TERM', True),
],
)
def test_ambiguous_reference_handling(term, expected_ambiguity, tmp_path, app, warning):
inv_file = tmp_path / 'inventory'
inv_file.write_bytes(INVENTORY_V2_AMBIGUOUS_TERMS)
set_config(
Expand All @@ -328,10 +335,11 @@ def test_ambiguous_reference_warning(tmp_path, app):
load_mappings(app)

# term reference (case insensitive)
node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM')
node, contnode = fake_node('std', 'term', term, term)
missing_reference(app, app.env, node, contnode)

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


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

0 comments on commit 655d1c7

Please sign in to comment.