(app: Sphinx, doctree: nodes.document)
| 156 | |
| 157 | |
| 158 | def 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 | |
| 206 | def _stable_abi_annotation( |
nothing calls this directly
no test coverage detected
searching dependent graphs…