8000 [3.12] Docs: Add classes to C API return value annotations (GH-117926… · python/cpython@67dc681 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67dc681

Browse files
miss-islingtonhugovksobolevn
authored
[3.12] Docs: Add classes to C API return value annotations (GH-117926) (#117937)
Docs: Add classes to C API return value annotations (GH-117926) (cherry picked from commit 3284b84) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent aa26dc3 commit 67dc681

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Doc/tools/extensions/c_annotations.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
c_annotations.py
43
~~~~~~~~~~~~~~~~
@@ -34,11 +33,10 @@
3433

3534
REST_ROLE_MAP = {
3635
'function': 'func',
37-
'var': 'data',
38-
'type': 'type',
3936
'macro': 'macro',
40-
'type': 'type',
4137
'member': 'member',
38+
'type': 'type',
39+
'var': 'data',
4240
}
4341

4442

@@ -63,15 +61,15 @@ def __init__(self, name):
6361
class Annotations:
6462
def __init__(self, refcount_filename, stable_abi_file):
6563
self.refcount_data = {}
66-
with open(refcount_filename, 'r') as fp:
64+
with open(refcount_filename, encoding='utf8') as fp:
6765
for line in fp:
6866
line = line.strip()
6967
if line[:1] in ("", "#"):
7068
# blank lines and comments
7169
continue
7270
parts = line.split(":", 4)
7371
if len(parts) != 5:
74-
raise ValueError("Wrong field count in %r" % line)
72+
raise ValueError(f"Wrong field count in {line!r}")
7573
function, type, arg, refcount, comment = parts
7674
# Get the entry, creating it if needed:
7775
try:
@@ -91,9 +89,8 @@ def __init__(self, refcount_filename, stable_abi_file):
9189
entry.result_refs = refcount
9290

9391
self.stable_abi_data = {}
94-
with open(stable_abi_file, 'r') as fp:
92+
with open(stable_abi_file, encoding='utf8') as fp:
9593
for record in csv.DictReader(fp):
96-
role = record['role']
9794
name = record['name']
9895
self.stable_abi_data[name] = record
9996

@@ -180,13 +177,17 @@ def add_annotations(self, app, doctree):
180177
continue
181178
elif not entry.result_type.endswith("Object*"):
182179
continue
180+
classes = ['refcount']
183181
if entry.result_refs is None:
184182
rc = sphinx_gettext('Return value: Always NULL.')
183+
classes.append('return_null')
185184
elif entry.result_refs:
186185
rc = sphinx_gettext('Return value: New reference.')
186+
classes.append('return_new_ref')
187187
else:
188188
rc = sphinx_gettext('Return value: Borrowed reference.')
189-
node.insert(0, nodes.emphasis(rc, rc, classes=['refcount']))
189+
classes.append('return_borrowed_ref')
190+
node.insert(0, nodes.emphasis(rc, rc, classes=classes))
190191

191192

192193
def init_annotations(app):
@@ -228,6 +229,7 @@ def setup(app):
228229
'stableabi': directives.flag,
229230
}
230231
old_handle_signature = CObject.handle_signature
232+
231233
def new_handle_signature(self, sig, signode):
232234
signode.parent['stableabi'] = 'stableabi' in self.options
233235
return old_handle_signature(self, sig, signode)

0 commit comments

Comments
 (0)
0