summaryrefslogtreecommitdiff
path: root/sphinx/domains/python.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-05-11 01:06:42 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-05-11 01:15:14 +0900
commit4ab0dba7555356e9f4ff2946a6b43fe4d1c82c78 (patch)
tree970248a89875590c2e642895b32d08e4dba54060 /sphinx/domains/python.py
parentd2c8cd3c803b27537a4d6f871279fce93d503d82 (diff)
downloadsphinx-git-4ab0dba7555356e9f4ff2946a6b43fe4d1c82c78.tar.gz
Fix #9205: py domain: canonical option causes xref resolution error
The :canonical: option causes "more than one target for cross-reference" warning because the class having the same name is registered.
Diffstat (limited to 'sphinx/domains/python.py')
-rw-r--r--sphinx/domains/python.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py
index 4464895ef..069737bde 100644
--- a/sphinx/domains/python.py
+++ b/sphinx/domains/python.py
@@ -1269,9 +1269,13 @@ class PythonDomain(Domain):
if not matches:
return None
elif len(matches) > 1:
- logger.warning(__('more than one target found for cross-reference %r: %s'),
- target, ', '.join(match[0] for match in matches),
- type='ref', subtype='python', location=node)
+ canonicals = [m for m in matches if not m[1].aliased]
+ if len(canonicals) == 1:
+ matches = canonicals
+ else:
+ logger.warning(__('more than one target found for cross-reference %r: %s'),
+ target, ', '.join(match[0] for match in matches),
+ type='ref', subtype='python', location=node)
name, obj = matches[0]
if obj[2] == 'module':