Skip to content

Commit 2418e00

Browse files
authored
Support unary subtraction in annotation parsing (#11904)
1 parent 7041f11 commit 2418e00

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

sphinx/domains/python/_annotations.py

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def unparse(node: ast.AST) -> list[Node]:
109109
return unparse(node.value)
110110
if isinstance(node, ast.Invert):
111111
return [addnodes.desc_sig_punctuation('', '~')]
112+
if isinstance(node, ast.USub):
113+
return [addnodes.desc_sig_punctuation('', '-')]
112114
if isinstance(node, ast.List):
113115
result = [addnodes.desc_sig_punctuation('', '[')]
114116
if node.elts:

tests/roots/test-domain-py/module.rst

+6
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ module
5858
.. py:module:: object
5959
6060
.. py:function:: sum()
61+
62+
.. py:data:: test
63+
:type: typing.Literal[2]
64+
65+
.. py:data:: test2
66+
:type: typing.Literal[-2]

tests/test_domains/test_domain_py.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ def assert_refnode(node, module_name, class_name, target, reftype=None,
133133
assert_refnode(refnodes[13], False, False, 'list', 'class')
134134
assert_refnode(refnodes[14], False, False, 'ModTopLevel', 'class')
135135
assert_refnode(refnodes[15], False, False, 'index', 'doc', domain='std')
136-
assert len(refnodes) == 16
136+
assert_refnode(refnodes[16], False, False, 'typing.Literal', 'obj', domain='py')
137+
assert_refnode(refnodes[17], False, False, 'typing.Literal', 'obj', domain='py')
138+
assert len(refnodes) == 18
137139

138140
doctree = app.env.get_doctree('module_option')
139141
refnodes = list(doctree.findall(pending_xref))

0 commit comments

Comments
 (0)