Skip to content

Commit

Permalink
Merge pull request #7454 from tk0miya/7445_rtype_annotation_None
Browse files Browse the repository at this point in the history
Fix #7445: a return annotation ``None`` is not converted to a hyperlink
  • Loading branch information
tk0miya committed Apr 10, 2020
2 parents aca3f82 + d9d381d commit ebf2571
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -19,6 +19,8 @@ Bugs fixed
----------

* #7428: py domain: a reference to class ``None`` emits a nitpicky warning
* #7445: py domain: a return annotation ``None`` in the function signature is
not converted to a hyperlink when using intersphinx
* #7418: std domain: duplication warning for glossary terms is case insensitive
* #7438: C++, fix merging overloaded functions in parallel builds.
* #7422: autodoc: fails with ValueError when using autodoc_mock_imports
Expand Down
7 changes: 6 additions & 1 deletion sphinx/domains/python.py
Expand Up @@ -71,8 +71,13 @@
def _parse_annotation(annotation: str) -> List[Node]:
"""Parse type annotation."""
def make_xref(text: str) -> addnodes.pending_xref:
if text == 'None':
reftype = 'obj'
else:
reftype = 'class'

return pending_xref('', nodes.Text(text),
refdomain='py', reftype='class', reftarget=text)
refdomain='py', reftype=reftype, reftarget=text)

def unparse(node: ast.AST) -> List[Node]:
if isinstance(node, ast.Attribute):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_domain_py.py
Expand Up @@ -239,6 +239,7 @@ def test_get_full_qualified_name():
def test_parse_annotation():
doctree = _parse_annotation("int")
assert_node(doctree, ([pending_xref, "int"],))
assert_node(doctree[0], pending_xref, refdomain="py", reftype="class", reftarget="int")

doctree = _parse_annotation("List[int]")
assert_node(doctree, ([pending_xref, "List"],
Expand Down Expand Up @@ -266,6 +267,12 @@ def test_parse_annotation():
[pending_xref, "int"],
[desc_sig_punctuation, "]"]))

# None type makes an object-reference (not a class reference)
doctree = _parse_annotation("None")
assert_node(doctree, ([pending_xref, "None"],))
assert_node(doctree[0], pending_xref, refdomain="py", reftype="obj", reftarget="None")



def test_pyfunction_signature(app):
text = ".. py:function:: hello(name: str) -> str"
Expand Down

0 comments on commit ebf2571

Please sign in to comment.