Skip to content

Commit

Permalink
:any: xref searches ignore aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Jablon committed Jan 17, 2022
1 parent bd55cce commit 8b8ec94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Features added
Bugs fixed
----------

* #9577, #10088: Fix warning for duplicate Python references when using :any:
and autodoc

Testing
--------

Expand Down
6 changes: 6 additions & 0 deletions sphinx/domains/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ def find_obj(self, env: BuildEnvironment, modname: str, classname: str,
matches = [(oname, self.objects[oname]) for oname in self.objects
if oname.endswith(searchname) and
self.objects[oname].objtype in objtypes]

else:
# NOTE: searching for exact match, object type is not considered
if name in self.objects:
Expand Down Expand Up @@ -1413,6 +1414,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',
Expand Down
3 changes: 3 additions & 0 deletions tests/roots/test-domain-py/canonical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ caninical
=========

:py:class:`.Foo`
:any:`Foo`
:any:`module.Foo`
:any:`original.module.Foo`

.. py:module:: canonical
Expand Down

0 comments on commit 8b8ec94

Please sign in to comment.