Extract classes, functions, and imports from a .py file via tree-sitter AST.
(path: Path, *, root: Path | None = None)
| 2464 | # ── Public API ──────────────────────────────────────────────────────────────── |
| 2465 | |
| 2466 | def extract_python(path: Path, *, root: Path | None = None) -> dict: |
| 2467 | """Extract classes, functions, and imports from a .py file via tree-sitter AST.""" |
| 2468 | result = _extract_generic(path, _PYTHON_CONFIG, scan_root=root) |
| 2469 | # Taken unconditionally: the slot must not outlive the call that filled it. |
| 2470 | parsed = take_python_parse(str(path)) |
| 2471 | if "error" not in result: |
| 2472 | _extract_python_rationale(path, result, parsed) |
| 2473 | return result |
| 2474 | |
| 2475 | |
| 2476 | _TS_TYPED_TAG_RE = re.compile( |