Extract documentation from a class.
(
cls: griffe_t.Class, class_name: str, config: dict
)
| 255 | |
| 256 | |
| 257 | def extract_class_info( |
| 258 | cls: griffe_t.Class, class_name: str, config: dict |
| 259 | ) -> dict[str, Any]: |
| 260 | """Extract documentation from a class.""" |
| 261 | griffe_module = load_griffe() |
| 262 | doc = parse_docstring(cls.docstring.value if cls.docstring else None) |
| 263 | |
| 264 | info = { |
| 265 | "name": class_name, |
| 266 | "access": config.get("access"), |
| 267 | "source_link": get_source_link(cls), |
| 268 | "description": doc["description"], |
| 269 | "deprecated": doc.get("deprecated"), |
| 270 | "properties": [], |
| 271 | "methods": [], |
| 272 | } |
| 273 | |
| 274 | # Extract properties/attributes |
| 275 | for name, member in cls.members.items(): |
| 276 | if name.startswith("_"): |
| 277 | continue |
| 278 | if isinstance(member, griffe_module.Attribute): |
| 279 | attr_doc = member.docstring.value if member.docstring else "" |
| 280 | info["properties"].append( |
| 281 | { |
| 282 | "name": name, |
| 283 | "type": format_type(member.annotation), |
| 284 | "description": attr_doc.strip() if attr_doc else "", |
| 285 | } |
| 286 | ) |
| 287 | |
| 288 | # Extract methods |
| 289 | for name, member in cls.members.items(): |
| 290 | if name.startswith("_"): |
| 291 | continue |
| 292 | if isinstance(member, griffe_module.Function): |
| 293 | method_doc = parse_docstring( |
| 294 | member.docstring.value if member.docstring else None |
| 295 | ) |
| 296 | |
| 297 | params = [] |
| 298 | for p in member.parameters: |
| 299 | if p.name in ("self", "cls"): |
| 300 | continue |
| 301 | params.append( |
| 302 | { |
| 303 | "name": p.name, |
| 304 | "type": format_type(p.annotation), |
| 305 | "optional": p.default is not None, |
| 306 | "description": method_doc["params"].get(p.name, ""), |
| 307 | } |
| 308 | ) |
| 309 | |
| 310 | info["methods"].append( |
| 311 | { |
| 312 | "name": name, |
| 313 | "source_link": get_source_link(member), |
| 314 | "description": method_doc["description"], |
no test coverage detected
searching dependent graphs…