Skip to content

Commit

Permalink
Close sphinx-doc#5977: :var: field do not create a cross-reference
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tk0miya committed Jan 1, 2021
1 parent 9cac200 commit aea424b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -22,6 +22,8 @@ Incompatible changes
``<div>``
* #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
----------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/python.py
Expand Up @@ -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),
Expand Down
4 changes: 1 addition & 3 deletions tests/test_domain_py.py
Expand Up @@ -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"})

Expand Down

0 comments on commit aea424b

Please sign in to comment.