Skip to content

Plan

plan

Move plan dataclass and related exceptions.

CallerRewrite dataclass

A single caller-import rewrite record for :class:MovePlan.

Source code in packages/axm-anvil/src/axm_anvil/core/callers.py
Python
@dataclass
class CallerRewrite:
    """A single caller-import rewrite record for :class:`MovePlan`."""

    file: str
    line: int
    old: str
    new: str

ImportCycleError

Bases: Exception

Raised when a move would introduce a new import cycle.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class ImportCycleError(Exception):
    """Raised when a move would introduce a new import cycle."""

    def __init__(self, cycle: list[str]) -> None:
        self.cycle = list(cycle)
        chain = " \u2192 ".join([*self.cycle, self.cycle[0]])
        super().__init__(f"Import cycle: {chain}")

MovePathError

Bases: Exception

Raised when source and target paths share no usable common base.

Computing the relative paths handed to batch_edit requires a base directory that contains both the source and the target. When the two live in disjoint trees (e.g. different drives) no such base exists, so the fallback raises this typed error instead of leaking a bare ValueError.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class MovePathError(Exception):
    """Raised when source and target paths share no usable common base.

    Computing the relative paths handed to ``batch_edit`` requires a base
    directory that contains *both* the source and the target. When the two
    live in disjoint trees (e.g. different drives) no such base exists, so the
    fallback raises this typed error instead of leaking a bare ``ValueError``.
    """

    def __init__(self, source: object, target: object) -> None:
        self.source = source
        self.target = target
        super().__init__(
            f"No common base directory contains both {source} and {target}"
        )

MovePlan dataclass

Result of a :func:move_symbols call.

Carries the rendered source and target texts, the names that were actually moved, and the direct dependencies (imports, constants) copied into the target. warnings aggregates non-fatal issues such as ruff post-processing errors.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
@dataclass
class MovePlan:
    """Result of a :func:`move_symbols` call.

    Carries the rendered source and target texts, the names that were
    actually moved, and the direct dependencies (imports, constants)
    copied into the target. ``warnings`` aggregates non-fatal issues
    such as ruff post-processing errors.
    """

    source_text_new: str
    target_text_new: str
    moved_names: list[str]
    imports_added: list[str] = field(default_factory=list)
    constants_added: list[str] = field(default_factory=list)
    warnings: list[str] = field(default_factory=list)
    shared_helpers_detected: list[SharedHelperDetection] = field(default_factory=list)
    callers_updated: list[CallerRewrite] = field(default_factory=list)

MoveValidationError

Bases: Exception

Raised when a rendered module fails to parse post-transform.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class MoveValidationError(Exception):
    """Raised when a rendered module fails to parse post-transform."""

    def __init__(self, text: str, cause: BaseException) -> None:
        super().__init__(f"Rendered module failed to parse: {cause}")
        self.text = text

OverloadPartialMoveError

Bases: Exception

Raised when only a subset of an overload group is requested.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class OverloadPartialMoveError(Exception):
    """Raised when only a subset of an overload group is requested."""

SharedHelperDetection dataclass

Classification record for a helper flagged as shared.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
@dataclass
class SharedHelperDetection:
    """Classification record for a helper flagged as shared."""

    name: str
    used_by_moved: list[str]
    used_by_remaining: list[str]

SharedHelpersError

Bases: Exception

Raised in error mode when shared helpers would be duplicated.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class SharedHelpersError(Exception):
    """Raised in ``error`` mode when shared helpers would be duplicated."""

    def __init__(self, shared_helpers: list[str]) -> None:
        self.shared_helpers = list(shared_helpers)
        joined = ", ".join(self.shared_helpers)
        super().__init__(
            f"Shared helpers detected (also used by remaining symbols): {joined}"
        )

SymbolAlreadyExistsError

Bases: Exception

Raised when a requested symbol already exists in the target module.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class SymbolAlreadyExistsError(Exception):
    """Raised when a requested symbol already exists in the target module."""

SymbolNotFoundError

Bases: Exception

Raised when a requested symbol does not exist in the source module.

Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
Python
class SymbolNotFoundError(Exception):
    """Raised when a requested symbol does not exist in the source module."""