From 8459887131c662e4de84a8ce3dd794c2d41ace48 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Tue, 11 Jan 2022 18:43:59 +0100 Subject: [PATCH] :any: xref searches ignore aliases --- CHANGES | 2 ++ sphinx/domains/python.py | 7 +++++++ tests/roots/test-domain-py/canonical.rst | 3 +++ 3 files changed, 12 insertions(+) diff --git a/CHANGES b/CHANGES index 19fa32ddb38..f79ae2c3d04 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,8 @@ Bugs fixed * #9096: sphinx-build: the value of progress bar for paralle build is wrong * #10110: sphinx-build: exit code is not changed when error is raised on builder-finished event +* #9577, #10088: Fix warning for duplicate Python references when using :any: + and autodoc Testing -------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index a634a51d2b2..2ba5af99746 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -1365,7 +1365,14 @@ def resolve_any_xref(self, env: BuildEnvironment, fromdocname: str, builder: Bui # always search in "refspecific" mode with the :any: role matches = self.find_obj(env, modname, clsname, target, None, 1) + multiple_matches = len(matches) > 1 + for name, obj in matches: + + if multiple_matches and obj.aliased: + # Skip duplicated matches + continue + if obj[2] == 'module': results.append(('py:mod', self._make_module_refnode(builder, fromdocname, diff --git a/tests/roots/test-domain-py/canonical.rst b/tests/roots/test-domain-py/canonical.rst index eff783aadde..34becfdfb69 100644 --- a/tests/roots/test-domain-py/canonical.rst +++ b/tests/roots/test-domain-py/canonical.rst @@ -2,6 +2,9 @@ caninical ========= :py:class:`.Foo` +:any:`Foo` +:any:`module.Foo` +:any:`original.module.Foo` .. py:module:: canonical