summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Lykke Andersen <Jakob@caput.dk>2021-09-25 12:52:52 +0200
committerJakob Lykke Andersen <Jakob@caput.dk>2021-10-02 12:41:40 +0200
commit51e7b6d2aa871c262e37f3fc9edbef67a2b3edd2 (patch)
treedea8afecacd2d9a8ce324e5748a3574f02f178a6
parent83fcc98dbcc04b09ccd55861f6f88b77acee1712 (diff)
downloadsphinx-git-51e7b6d2aa871c262e37f3fc9edbef67a2b3edd2.tar.gz
py nodes, PyClassLike, get_signature_prefix
-rw-r--r--sphinx/domains/python.py7
-rw-r--r--tests/test_domain_py.py27
2 files changed, 19 insertions, 15 deletions
diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py
index 999a00dcf..f042274a7 100644
--- a/sphinx/domains/python.py
+++ b/sphinx/domains/python.py
@@ -714,11 +714,12 @@ class PyClasslike(PyObject):
allow_nesting = True
- def get_signature_prefix(self, sig: str) -> str:
+ def get_signature_prefix(self, sig: str) -> List[nodes.Node]:
if 'final' in self.options:
- return 'final %s ' % self.objtype
+ return [nodes.Text('final'), addnodes.desc_sig_space(),
+ nodes.Text(self.objtype), addnodes.desc_sig_space()]
else:
- return '%s ' % self.objtype
+ return [nodes.Text(self.objtype), addnodes.desc_sig_space()]
def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str:
if self.objtype == 'class':
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py
index 36b327854..84a918b90 100644
--- a/tests/test_domain_py.py
+++ b/tests/test_domain_py.py
@@ -520,7 +520,7 @@ def test_pyexception_signature(app):
text = ".. py:exception:: builtins.IOError"
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "exception "],
+ [desc, ([desc_signature, ([desc_annotation, ('exception', desc_sig_space)],
[desc_addname, "builtins."],
[desc_name, "IOError"])],
desc_content)]))
@@ -583,7 +583,7 @@ def test_pyobject_prefix(app):
" .. py:method:: FooBar.say")
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ('class', desc_sig_space)],
[desc_name, "Foo"])],
[desc_content, (addnodes.index,
desc,
@@ -653,11 +653,14 @@ def test_pyclass_options(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_name, "Class1"])],
[desc_content, ()])],
addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "final class "],
+ [desc, ([desc_signature, ([desc_annotation, ("final",
+ desc_sig_space,
+ "class",
+ desc_sig_space)],
[desc_name, "Class2"])],
[desc_content, ()])]))
@@ -693,7 +696,7 @@ def test_pymethod_options(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_name, "Class"])],
[desc_content, (addnodes.index,
desc,
@@ -786,7 +789,7 @@ def test_pyclassmethod(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_name, "Class"])],
[desc_content, (addnodes.index,
desc)])]))
@@ -807,7 +810,7 @@ def test_pystaticmethod(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_name, "Class"])],
[desc_content, (addnodes.index,
desc)])]))
@@ -830,7 +833,7 @@ def test_pyattribute(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_name, "Class"])],
[desc_content, (addnodes.index,
desc)])]))
@@ -868,7 +871,7 @@ def test_pyproperty(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_name, "Class"])],
[desc_content, (addnodes.index,
desc,
@@ -932,7 +935,7 @@ def test_canonical(app):
domain = app.env.get_domain('py')
doctree = restructuredtext.parse(app, text)
assert_node(doctree, (addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_addname, "io."],
[desc_name, "StringIO"])],
desc_content)]))
@@ -990,7 +993,7 @@ def test_info_field_list(app):
assert_node(doctree, (nodes.target,
addnodes.index,
addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_addname, "example."],
[desc_name, "Class"])],
[desc_content, nodes.field_list, nodes.field])]))
@@ -1081,7 +1084,7 @@ def test_info_field_list_piped_type(app):
(nodes.target,
addnodes.index,
addnodes.index,
- [desc, ([desc_signature, ([desc_annotation, "class "],
+ [desc, ([desc_signature, ([desc_annotation, ("class", desc_sig_space)],
[desc_addname, "example."],
[desc_name, "Class"])],
[desc_content, nodes.field_list, nodes.field, (nodes.field_name,