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 13, 2022
1 parent 3ed9265 commit e9eb629
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Bugs fixed
* #9979: Error level messages were displayed as warning messages
* #10057: Failed to scan documents if the project is placed onto the root
directory
* #9577, #10088: Fix warning for duplicate Python references when using :any:
and autodoc

Testing
--------
Expand Down
12 changes: 12 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,17 @@ 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 (when there are multiple matches for the
# same node_id, keep only the one that is not aliased)
original_matches = {obj.node_id for _, obj in matches if not obj.aliased}
matches = [
(name, obj)
for name, obj in matches
if obj.node_id not in original_matches or 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 e9eb629

Please sign in to comment.