Skip to content

Commit 6b05026

Browse files
committed
gh-140014: Wrap C API annotations in a paragraph.
It turns out putting <emphasis> directly in <desc_content> is not valid docutils. Sphinx doesn't detect this, though.
1 parent 713be70 commit 6b05026

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Doc/tools/extensions/c_annotations.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ def add_annotations(app: Sphinx, doctree: nodes.document) -> None:
126126
name = par[0]["ids"][0].removeprefix("c.")
127127
objtype = par["objtype"]
128128

129+
annotations = []
130+
131+
# Return value annotation
132+
if objtype == "function" and name in refcount_data:
133+
entry = refcount_data[name]
134+
if entry.result_type.endswith("Object*"):
135+
annotations.append(_return_value_annotation(entry.result_refs))
136+
129137
# Stable ABI annotation.
130138
if record := stable_abi_data.get(name):
131139
if ROLE_TO_OBJECT_TYPE[record.role] != objtype:
@@ -134,24 +142,19 @@ def add_annotations(app: Sphinx, doctree: nodes.document) -> None:
134142
f"{ROLE_TO_OBJECT_TYPE[record.role]!r} != {objtype!r}"
135143
)
136144
raise ValueError(msg)
137-
annotation = _stable_abi_annotation(record)
138-
node.insert(0, annotation)
145+
annotations.append(_stable_abi_annotation(record))
139146

140147
# Unstable API annotation.
141148
if name.startswith("PyUnstable"):
142-
annotation = _unstable_api_annotation()
143-
node.insert(0, annotation)
144-
145-
# Return value annotation
146-
if objtype != "function":
147-
continue
148-
if name not in refcount_data:
149-
continue
150-
entry = refcount_data[name]
151-
if not entry.result_type.endswith("Object*"):
152-
continue
153-
annotation = _return_value_annotation(entry.result_refs)
154-
node.insert(0, annotation)
149+
annotations.append(_unstable_api_annotation())
150+
151+
if annotations:
152+
para = nodes.paragraph(' ', ' ', classes=['c_annotations'])
153+
for idx, annotation in enumerate(annotations):
154+
if idx:
155+
para.append(nodes.Text(" "))
156+
para.append(annotation)
157+
node.insert(0, para)
155158

156159

157160
def _stable_abi_annotation(

0 commit comments

Comments
 (0)