Skip to content

Changed lines

changed_lines

Map changed line intervals to qualified symbols, including function bodies.

symbols_for_lines(package, file, intervals)

Return stable module-qualified seeds for changed lines in an AST snapshot.

Class containers remain seeds beside changed methods. Module-level changes (imports, declarations outside a symbol) conservatively seed every symbol of the module. Call this on both base and head to cover deleted symbols.

Source code in packages/axm-ast/src/axm_ast/core/changed_lines.py
Python
def symbols_for_lines(
    package: Path,
    file: Path,
    intervals: Sequence[tuple[int, int]],
) -> tuple[str, ...]:
    """Return stable module-qualified seeds for changed lines in an AST snapshot.

    Class containers remain seeds beside changed methods. Module-level changes
    (imports, declarations outside a symbol) conservatively seed every symbol
    of the module. Call this on both base and head to cover deleted symbols.
    """
    pkg = get_package(package)
    module = next((m for m in pkg.modules if m.path.resolve() == file.resolve()), None)
    if module is None:
        return ()
    relative = module.path.relative_to(pkg.root).with_suffix("")
    parts = list(relative.parts)
    if parts and parts[-1] == "__init__":
        parts.pop()
    prefix = ".".join([pkg.name, *parts])
    selected = _selected_symbols(_symbols(module), intervals)
    return tuple(sorted({prefix + "." + name for name in selected}))