MCPcopy Index your code
hub / github.com/python/cpython / add_annotations

Function add_annotations

Doc/tools/extensions/c_annotations.py:158–203  ·  view source on GitHub ↗
(app: Sphinx, doctree: nodes.document)

Source from the content-addressed store, hash-verified

156
157
158def add_annotations(app: Sphinx, doctree: nodes.document) -> None:
159 state = app.env.domaindata["c_annotations"]
160 refcount_data = state["refcount_data"]
161 stable_abi_data = state["stable_abi_data"]
162 threadsafety_data = state["threadsafety_data"]
163 for node in doctree.findall(addnodes.desc_content):
164 par = node.parent
165 if par["domain"] != "c":
166 continue
167 if not par[0].get("ids", None):
168 continue
169 name = par[0]["ids"][0].removeprefix("c.")
170 objtype = par["objtype"]
171
172 # Thread safety annotation — inserted first so it appears last (bottom-most)
173 # among all annotations.
174 if entry := threadsafety_data.get(name):
175 annotation = _threadsafety_annotation(entry.level)
176 node.insert(0, annotation)
177
178 # Stable ABI annotation.
179 if record := stable_abi_data.get(name):
180 if ROLE_TO_OBJECT_TYPE[record.role] != objtype:
181 msg = (
182 f"Object type mismatch in limited API annotation for {name}: "
183 f"{ROLE_TO_OBJECT_TYPE[record.role]!r} != {objtype!r}"
184 )
185 raise ValueError(msg)
186 annotation = _stable_abi_annotation(record)
187 node.insert(0, annotation)
188
189 # Unstable API annotation.
190 if name.startswith("PyUnstable"):
191 annotation = _unstable_api_annotation()
192 node.insert(0, annotation)
193
194 # Return value annotation
195 if objtype != "function":
196 continue
197 if name not in refcount_data:
198 continue
199 entry = refcount_data[name]
200 if not entry.result_type.endswith("Object*"):
201 continue
202 annotation = _return_value_annotation(entry.result_refs)
203 node.insert(0, annotation)
204
205
206def _stable_abi_annotation(

Callers

nothing calls this directly

Calls 10

_threadsafety_annotationFunction · 0.85
_stable_abi_annotationFunction · 0.85
_unstable_api_annotationFunction · 0.85
_return_value_annotationFunction · 0.85
findallMethod · 0.45
getMethod · 0.45
removeprefixMethod · 0.45
insertMethod · 0.45
startswithMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…