From 86b89b6adb1057535e30a1dc9fe848123ad78664 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Tue, 11 Jan 2022 18:43:59 +0100 Subject: [PATCH 1/3] :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 106ac274202..810d90c25d4 100644 --- a/CHANGES +++ b/CHANGES @@ -32,6 +32,8 @@ Bugs fixed * #10520: HTML Theme: Fix use of sidebar classes in ``agogo.css_t``. * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work +* #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 fd43b15b262..370244a4362 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 From 52765ca9ca5047cfda60a50ad1745d1de8af2f85 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 26 Jun 2022 12:56:03 +0100 Subject: [PATCH 2/3] Update CHANGES --- CHANGES | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 810d90c25d4..eacb27dad93 100644 --- a/CHANGES +++ b/CHANGES @@ -32,7 +32,8 @@ Bugs fixed * #10520: HTML Theme: Fix use of sidebar classes in ``agogo.css_t``. * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work -* #9577, #10088: Fix warning for duplicate Python references when using :any: +* #9577, #10088: py domain: Fix warning for duplicate Python references when + using :any: and autodoc Testing From 1345ddd50474d0dbef02e217bdbb2b34f3c437a6 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 26 Jun 2022 12:57:00 +0100 Subject: [PATCH 3/3] Update CHANGES --- CHANGES | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index eacb27dad93..7e5e372f6c1 100644 --- a/CHANGES +++ b/CHANGES @@ -33,8 +33,7 @@ Bugs fixed * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work * #9577, #10088: py domain: Fix warning for duplicate Python references when - using :any: - and autodoc + using ``:any:`` and autodoc. Testing --------