From 2db006a0afe9a20376a4c5dee3bda2ad3da48002 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 21 Feb 2020 01:22:24 +0900 Subject: [PATCH] Fix #7183: intersphinx: ``:attr:`` reference to property is broken --- CHANGES | 1 + sphinx/ext/intersphinx.py | 3 +++ tests/test_ext_intersphinx.py | 6 ++++++ tests/test_util_inventory.py | 1 + 4 files changed, 11 insertions(+) diff --git a/CHANGES b/CHANGES index a34909ae98f..e49006b268a 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,7 @@ Bugs fixed * #7184: autodoc: ``*args`` and ``**kwarg`` in type comments are not handled properly +* #7183: intersphinx: ``:attr:`` reference to property is broken Testing -------- diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index da0988b799a..362583fa2cb 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -282,6 +282,9 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: Element, contnod if 'std:cmdoption' in objtypes: # until Sphinx-1.6, cmdoptions are stored as std:option objtypes.append('std:option') + if 'py:attribute' in objtypes: + # Since Sphinx-2.1, properties are stored as py:method + objtypes.append('py:method') to_try = [(inventories.main_inventory, target)] if domain: full_qualified_name = env.get_domain(domain).get_full_qualified_name(node) diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py index ba377f2a0a0..eac2394c879 100644 --- a/tests/test_ext_intersphinx.py +++ b/tests/test_ext_intersphinx.py @@ -190,6 +190,12 @@ def test_missing_reference_pydomain(tempdir, app, status, warning): rn = missing_reference(app, app.env, node, contnode) assert rn.astext() == 'func()' + # py:attr context helps to search objects + kwargs = {'py:module': 'module1'} + node, contnode = fake_node('py', 'attr', 'Foo.bar', 'Foo.bar', **kwargs) + rn = missing_reference(app, app.env, node, contnode) + assert rn.astext() == 'Foo.bar' + def test_missing_reference_stddomain(tempdir, app, status, warning): inv_file = tempdir / 'inventory' diff --git a/tests/test_util_inventory.py b/tests/test_util_inventory.py index 7491b217d71..2183313e1e8 100644 --- a/tests/test_util_inventory.py +++ b/tests/test_util_inventory.py @@ -31,6 +31,7 @@ module1 py:module 0 foo.html#module-module1 Long Module desc module2 py:module 0 foo.html#module-$ - module1.func py:function 1 sub/foo.html#$ - +module1.Foo.bar py:method 1 index.html#foo.Bar.baz - CFunc c:function 2 cfunc.html#CFunc - std cpp:type 1 index.html#std - std::uint8_t cpp:type 1 index.html#std_uint8_t -