Rename
rename
In-place symbol rename across a workspace.
:func:rename_symbols renames one or more top-level symbols in place in
their defining module (definition + internal usages) and rewrites every
cross-file caller that imports the renamed names from that module. Unlike
:func:axm_anvil.core.move.move_symbols, no block is copied between files:
the symbol keeps its module, only its name changes.
The rewrite reuses :class:axm_anvil._cst.transformers.RenameSymbols for
both the defining module and the callers. Applied to a caller, RenameSymbols
rewrites the imported alias (from mod import Old -> from mod import New)
and every bare-name usage in a single pass; attribute members (obj.Old)
are deliberately left untouched.
Caller discovery is pattern-based on the import statement (it scans for
from <module> import <name> via :func:_discover_callers). The following
cases are intentionally NOT handled and are deferred to Tier 2.1:
- shadowing — a local binding named like a renamed symbol in a caller is rewritten blindly (no scope analysis on the rename path);
- aliased imports / alias chains —
from mod import Old as Orewrites theOldtoken but downstreamOusages are not reconciled; - re-exports / star imports — symbols reached through
import *or a re-export module are not discovered.
RenamePlan
dataclass
Result of a :func:rename_symbols call.
Carries the rewritten text of the defining module, the names that were
actually renamed (old -> new), the caller-file rewrites and any
non-fatal warnings (e.g. a requested symbol that was absent in
non-strict mode).
Source code in packages/axm-anvil/src/axm_anvil/core/rename.py
rename_symbols(path, file, mapping, *, dry_run=False, workspace_root=None, strict=False)
Rename top-level symbols in file and rewrite cross-file callers.
Parameters
path:
Workspace root used to resolve a relative file and to constrain
caller discovery.
file:
Python file defining the symbols. Relative paths resolve against
path.
mapping:
{old_name: new_name} for the top-level symbols to rename.
dry_run:
When True, compute the :class:RenamePlan without writing.
workspace_root:
Explicit workspace root; falls back to the nearest ancestor with a
pyproject.toml when None.
strict:
When True a requested old name absent from the module raises
:class:SymbolNotFoundError; when False (default) it is skipped
with a warning on :attr:RenamePlan.warnings.
Returns
RenamePlan The rewritten module text, the active renames, caller rewrites and warnings. Caller rewriting is pattern-based on imports; see the module docstring for the uncovered cases.