Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7445: a return annotation None is not converted to a hyperlink #7454

Merged
merged 1 commit into from Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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