Merge pull request #7454 from tk0miya/7445_rtype_annotation_None

Fix #7445: a return annotation ``None`` is not converted to a hyperlink
This commit is contained in:
Takeshi KOMIYA 2020-04-10 23:04:24 +09:00 committed by GitHub
commit ebf2571380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -19,6 +19,8 @@ Bugs fixed
---------- ----------
* #7428: py domain: a reference to class ``None`` emits a nitpicky warning * #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 * #7418: std domain: duplication warning for glossary terms is case insensitive
* #7438: C++, fix merging overloaded functions in parallel builds. * #7438: C++, fix merging overloaded functions in parallel builds.
* #7422: autodoc: fails with ValueError when using autodoc_mock_imports * #7422: autodoc: fails with ValueError when using autodoc_mock_imports

View File

@ -71,8 +71,13 @@ pairindextypes = {
def _parse_annotation(annotation: str) -> List[Node]: def _parse_annotation(annotation: str) -> List[Node]:
"""Parse type annotation.""" """Parse type annotation."""
def make_xref(text: str) -> addnodes.pending_xref: def make_xref(text: str) -> addnodes.pending_xref:
if text == 'None':
reftype = 'obj'
else:
reftype = 'class'
return pending_xref('', nodes.Text(text), 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]: def unparse(node: ast.AST) -> List[Node]:
if isinstance(node, ast.Attribute): if isinstance(node, ast.Attribute):

View File

@ -239,6 +239,7 @@ def test_get_full_qualified_name():
def test_parse_annotation(): def test_parse_annotation():
doctree = _parse_annotation("int") doctree = _parse_annotation("int")
assert_node(doctree, ([pending_xref, "int"],)) assert_node(doctree, ([pending_xref, "int"],))
assert_node(doctree[0], pending_xref, refdomain="py", reftype="class", reftarget="int")
doctree = _parse_annotation("List[int]") doctree = _parse_annotation("List[int]")
assert_node(doctree, ([pending_xref, "List"], assert_node(doctree, ([pending_xref, "List"],
@ -266,6 +267,12 @@ def test_parse_annotation():
[pending_xref, "int"], [pending_xref, "int"],
[desc_sig_punctuation, "]"])) [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): def test_pyfunction_signature(app):
text = ".. py:function:: hello(name: str) -> str" text = ".. py:function:: hello(name: str) -> str"