Repository: sphinx-doc/sphinx

Issue:
sphinx 1.8.0 :type: can't process :term: references
### Problem
As of sphinx 1.8.0 `:term:` references in a `:type:` no longer appear to work.

#### Procedure to reproduce the problem
Use this rst:
```
.. glossary::

    test
        data


.. currentmodule:: foo.bar

.. class:: Baz

    .. attribute:: quux

        :type: :term:`test`
```
Then run sphinx-build against it with a default conf and you'll see: `WARNING: py:class reference target not found: test`

In 1.7.9 and before this would properly link.

#### Environment
* Python 3.7
* macOS 10.13
* sphinx 1.8.0

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=h1) Report
> Merging [#5467](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=desc) into [1.8](https://codecov.io/gh/sphinx-doc/sphinx/commit/a2748f787c5f9ba0d860719be59d80d08e14b3e9?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/graphs/tree.svg?width=650&token=VFlFSELbkw&height=150&src=pr)](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##              1.8    #5467      +/-   ##
==========================================
+ Coverage   82.04%   82.04%   +<.01%     
==========================================
  Files         300      306       +6     
  Lines       40020    40359     +339     
  Branches     6182     6236      +54     
==========================================
+ Hits        32834    33114     +280     
- Misses       5809     5862      +53     
- Partials     1377     1383       +6
```


| [Impacted Files](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [sphinx/util/docfields.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L3V0aWwvZG9jZmllbGRzLnB5) | `88.7% <0%> (ø)` | :arrow_up: |
| [sphinx/make\_mode.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L21ha2VfbW9kZS5weQ==) | `0% <0%> (ø)` | |
| [sphinx/search/\_\_init\_\_.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L3NlYXJjaC9fX2luaXRfXy5weQ==) | `96.9% <0%> (ø)` | |
| [sphinx/quickstart.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L3F1aWNrc3RhcnQucHk=) | `0% <0%> (ø)` | |
| [sphinx/errors.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L2Vycm9ycy5weQ==) | `80% <0%> (ø)` | |
| [sphinx/\_\_init\_\_.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L19faW5pdF9fLnB5) | `60% <0%> (ø)` | |
| [sphinx/apidoc.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L2FwaWRvYy5weQ==) | `0% <0%> (ø)` | |
| [sphinx/builders/html.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467/diff?src=pr&el=tree#diff-c3BoaW54L2J1aWxkZXJzL2h0bWwucHk=) | `82.93% <0%> (+0.09%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=footer). Last update [a2748f7...190b393](https://codecov.io/gh/sphinx-doc/sphinx/pull/5467?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGES b/CHANGES
index 87f3b519a..16edc8042 100644
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,7 @@ Bugs fixed
 * #5453: PDF builds of 'howto' documents have no page numbers
 * #5463: mathbase: math_role and MathDirective was disappeared in 1.8.0
 * #5454: latex: Index has disappeared from PDF for Japanese documents
+* #5432: py domain: ``:type:`` field can't process ``:term:`` references
 
 Testing
 --------
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index 202616337..2b8cb6425 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -305,7 +305,8 @@ def transform(self, node):
                 entries.append(field)
 
                 # but if this has a type then we can at least link it
-                if typedesc and is_typefield and content:
+                if (typedesc and is_typefield and content and
+                        len(content) == 1 and isinstance(content[0], nodes.Text)):
                     target = content[0].astext()
                     xrefs = typedesc.make_xrefs(
                         typedesc.typerolename,


Test patch:
diff --git a/tests/roots/test-domain-py/module.rst b/tests/roots/test-domain-py/module.rst
index 509be6c3b..64601bc95 100644
--- a/tests/roots/test-domain-py/module.rst
+++ b/tests/roots/test-domain-py/module.rst
@@ -38,3 +38,10 @@ module
    :type  y: tuple(str, float)
    :rtype:   list
 
+.. py:attribute:: attr1
+
+   :type: ModTopLevel
+
+.. py:attribute:: attr2
+
+   :type: :doc:`index`
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py
index 8e93986fa..44205f539 100644
--- a/tests/test_domain_py.py
+++ b/tests/test_domain_py.py
@@ -113,7 +113,10 @@ def assert_refnode(node, module_name, class_name, target, reftype=None,
     assert_refnode(refnodes[9], False, False, 'str', 'class')
     assert_refnode(refnodes[10], False, False, 'float', 'class')
     assert_refnode(refnodes[11], False, False, 'list', 'class')
-    assert len(refnodes) == 12
+    assert_refnode(refnodes[11], False, False, 'list', 'class')
+    assert_refnode(refnodes[12], False, False, 'ModTopLevel', 'class')
+    assert_refnode(refnodes[13], False, False, 'index', 'doc', domain='std')
+    assert len(refnodes) == 14
 
     doctree = app.env.get_doctree('module_option')
     refnodes = list(doctree.traverse(addnodes.pending_xref))