mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Support unary subtraction in annotation parsing (#11904)
This commit is contained in:
@@ -109,6 +109,8 @@ def _parse_annotation(annotation: str, env: BuildEnvironment) -> list[Node]:
|
||||
return unparse(node.value)
|
||||
if isinstance(node, ast.Invert):
|
||||
return [addnodes.desc_sig_punctuation('', '~')]
|
||||
if isinstance(node, ast.USub):
|
||||
return [addnodes.desc_sig_punctuation('', '-')]
|
||||
if isinstance(node, ast.List):
|
||||
result = [addnodes.desc_sig_punctuation('', '[')]
|
||||
if node.elts:
|
||||
|
||||
@@ -58,3 +58,9 @@ module
|
||||
.. py:module:: object
|
||||
|
||||
.. py:function:: sum()
|
||||
|
||||
.. py:data:: test
|
||||
:type: typing.Literal[2]
|
||||
|
||||
.. py:data:: test2
|
||||
:type: typing.Literal[-2]
|
||||
|
||||
@@ -133,7 +133,9 @@ def test_domain_py_xrefs(app, status, warning):
|
||||
assert_refnode(refnodes[13], False, False, 'list', 'class')
|
||||
assert_refnode(refnodes[14], False, False, 'ModTopLevel', 'class')
|
||||
assert_refnode(refnodes[15], False, False, 'index', 'doc', domain='std')
|
||||
assert len(refnodes) == 16
|
||||
assert_refnode(refnodes[16], False, False, 'typing.Literal', 'obj', domain='py')
|
||||
assert_refnode(refnodes[17], False, False, 'typing.Literal', 'obj', domain='py')
|
||||
assert len(refnodes) == 18
|
||||
|
||||
doctree = app.env.get_doctree('module_option')
|
||||
refnodes = list(doctree.findall(pending_xref))
|
||||
|
||||
Reference in New Issue
Block a user