mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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.
This commit is contained in:
parent
d2c8cd3c80
commit
4ab0dba755
2
CHANGES
2
CHANGES
@ -22,6 +22,8 @@ Bugs fixed
|
|||||||
autosummary_generate
|
autosummary_generate
|
||||||
* #8380: html search: tags for search result are broken
|
* #8380: html search: tags for search result are broken
|
||||||
* #9198: i18n: Babel emits errors when running compile_catalog
|
* #9198: i18n: Babel emits errors when running compile_catalog
|
||||||
|
* #9205: py domain: The :canonical: option causes "more than one target for
|
||||||
|
cross-reference" warning
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -1269,9 +1269,13 @@ class PythonDomain(Domain):
|
|||||||
if not matches:
|
if not matches:
|
||||||
return None
|
return None
|
||||||
elif len(matches) > 1:
|
elif len(matches) > 1:
|
||||||
logger.warning(__('more than one target found for cross-reference %r: %s'),
|
canonicals = [m for m in matches if not m[1].aliased]
|
||||||
target, ', '.join(match[0] for match in matches),
|
if len(canonicals) == 1:
|
||||||
type='ref', subtype='python', location=node)
|
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]
|
name, obj = matches[0]
|
||||||
|
|
||||||
if obj[2] == 'module':
|
if obj[2] == 'module':
|
||||||
|
9
tests/roots/test-domain-py/canonical.rst
Normal file
9
tests/roots/test-domain-py/canonical.rst
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
caninical
|
||||||
|
=========
|
||||||
|
|
||||||
|
:py:class:`.Foo`
|
||||||
|
|
||||||
|
.. py:module:: canonical
|
||||||
|
|
||||||
|
.. py:class:: Foo
|
||||||
|
:canonical: original.module.Foo
|
@ -5,3 +5,6 @@ test-domain-py
|
|||||||
|
|
||||||
roles
|
roles
|
||||||
module
|
module
|
||||||
|
module_option
|
||||||
|
abbr
|
||||||
|
canonical
|
||||||
|
@ -236,6 +236,17 @@ def test_domain_py_find_obj(app, status, warning):
|
|||||||
('roles', 'NestedParentA.NestedChildA.subchild_1', 'method', False))])
|
('roles', 'NestedParentA.NestedChildA.subchild_1', 'method', False))])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='domain-py', freshenv=True)
|
||||||
|
def test_domain_py_canonical(app, status, warning):
|
||||||
|
app.builder.build_all()
|
||||||
|
|
||||||
|
content = (app.outdir / 'canonical.html').read_text()
|
||||||
|
assert ('<a class="reference internal" href="#canonical.Foo" title="canonical.Foo">'
|
||||||
|
'<code class="xref py py-class docutils literal notranslate">'
|
||||||
|
'<span class="pre">Foo</span></code></a>' in content)
|
||||||
|
assert warning.getvalue() == ''
|
||||||
|
|
||||||
|
|
||||||
def test_get_full_qualified_name():
|
def test_get_full_qualified_name():
|
||||||
env = Mock(domaindata={})
|
env = Mock(domaindata={})
|
||||||
domain = PythonDomain(env)
|
domain = PythonDomain(env)
|
||||||
|
Loading…
Reference in New Issue
Block a user