Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions loopx/semantics/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ast
from collections import defaultdict
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
import re
import subprocess
Expand Down Expand Up @@ -115,7 +116,15 @@ def _assigned_name(node: ast.AST) -> tuple[str, ast.AST] | None:
return None


@lru_cache(maxsize=4096)
def python_facts(source: SourceFile) -> dict[str, list[dict[str, Any]]]:
"""Inventory the Python facts of one source file.

The cache is keyed by the frozen SourceFile (path, suffix, text), so a
mutated file is a different key and never serves stale facts; repeated
scans of the same tree (owner_values plus build_inventory in the drift
smoke) parse each file once instead of once per caller.
"""
facts: dict[str, list[dict[str, Any]]] = {
"enums": [],
"closed_sets": [],
Expand Down