From aea424b2a2a564357d208f995ed5c88d9bd3ed40 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 1 Jan 2021 19:51:59 +0900 Subject: [PATCH] Close #5977: :var: field do not create a cross-reference Since its beginning, `:var:` field has created a cross-reference to the attribute having the same name. It is meaningful only if the attribute is documented by `py:attribute` directive. It means the `:var:` field and `:attr:` role are almost the same and conflicted. Additonally, the cross-reference points incorrect variable if the target is not documented. Thus, the cross-reference feature of `:var:` field is disabled. --- CHANGES | 2 ++ sphinx/domains/python.py | 2 +- tests/test_domain_py.py | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 9c889420fd..d8a0675836 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,8 @@ Incompatible changes ``
`` * #8508: LaTeX: uplatex becomes a default setting of latex_engine for Japanese documents +* #5977: py domain: ``:var:``, ``:cvar:`` and ``:ivar:`` fields do not create + cross-references Deprecated ---------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 000e2e8d34..5afe2993a4 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -354,7 +354,7 @@ class PyObject(ObjectDescription): 'keyword', 'kwarg', 'kwparam'), typerolename='class', typenames=('paramtype', 'type'), can_collapse=True), - PyTypedField('variable', label=_('Variables'), rolename='obj', + PyTypedField('variable', label=_('Variables'), names=('var', 'ivar', 'cvar'), typerolename='class', typenames=('vartype',), can_collapse=True), diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py index 14e9334486..537bae15bb 100644 --- a/tests/test_domain_py.py +++ b/tests/test_domain_py.py @@ -852,14 +852,12 @@ def test_info_field_list_var(app): # :var int attr: assert_node(doctree[1][1][0][0][1][0], - ([pending_xref, addnodes.literal_strong, "attr"], + ([addnodes.literal_strong, "attr"], " (", [pending_xref, addnodes.literal_emphasis, "int"], ")", " -- ", "blah blah")) - assert_node(doctree[1][1][0][0][1][0][0], pending_xref, - refdomain="py", reftype="obj", reftarget="attr", **{"py:class": "Class"}) assert_node(doctree[1][1][0][0][1][0][2], pending_xref, refdomain="py", reftype="class", reftarget="int", **{"py:class": "Class"})