diff --git a/CHANGES b/CHANGES index 2ce9ac36649..c8e8d0ecdd5 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #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 145b62eda8c..36f7ec9c474 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -1413,6 +1413,11 @@ 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) + + if len(matches) > 1: + # Remove all duplicated matches + matches = [(name, obj) for name, obj in matches if not obj.aliased] + for name, obj in matches: if obj[2] == 'module': results.append(('py:mod', 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