diff --git a/CHANGES b/CHANGES index 9dedf1523e3..4a2059d18e5 100644 --- a/CHANGES +++ b/CHANGES @@ -37,6 +37,8 @@ Bugs fixed * #8686: LaTeX: Text can fall out of code-block at end of page and leave artifact on next page * #10579: i18n: UnboundLocalError is raised on translating raw directive +* #9577, #10088: py domain: 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