Implementation:Wandb Weave Legacy Methods Lint Rules
| Knowledge Sources | |
|---|---|
| Domains | Code_Quality, Static_Analysis |
| Last Updated | 2026-02-14 10:53 GMT |
Overview
Concrete tool for enforcing migration from deprecated Weave client methods and classes to their modern replacements, provided by the Fixit lint framework.
Description
The legacy_methods.py module defines four CST-based lint rules using libcst for AST-level analysis and auto-fixing via the Fixit framework. Three rules handle deprecated client method renaming: ClientCallsRule rewrites `client.calls()` to `client.get_calls()`, ClientCallRule rewrites `client.call()` to `client.get_call()`, and ClientFeedbackRule rewrites `client.feedback()` to `client.get_feedback()`. A fourth rule, ReplaceFileWithContentRule, uses the `QualifiedNameProvider` metadata to precisely match `weave.type_handlers.File.File` instantiations and rewrites them to `Content.from_path(...)`, preserving all arguments. Each rule extends Fixit's `LintRule` base class, implements `visit_Call`, and provides both a diagnostic message and an auto-fix replacement node.
Usage
These lint rules are enabled in pyproject.toml under `[tool.fixit]` as `.rules.legacy_methods`. They fire automatically during `fixit lint` or `fixit fix` runs. Use these rules when migrating codebases from deprecated Weave client APIs to the current API surface, or when enforcing that the deprecated `File` class is replaced by `Content.from_path`.
Code Reference
Source Location
- Repository: Wandb_Weave
- File: rules/legacy_methods.py
- Lines: 1-182
Signature
class ClientCallsRule(LintRule):
"""Convert client.calls() to client.get_calls()."""
VALID = [Valid("client.get_calls")]
INVALID = [Invalid("client.calls")]
def visit_Call(self, node: libcst.Call) -> None: ...
class ClientCallRule(LintRule):
"""Convert client.call() to client.get_call()."""
VALID = [Valid("client.get_call")]
INVALID = [Invalid("client.call")]
def visit_Call(self, node: libcst.Call) -> None: ...
class ClientFeedbackRule(LintRule):
"""Convert client.feedback() to client.get_feedback()."""
VALID = [Valid("client.get_feedback")]
INVALID = [Invalid("client.feedback")]
def visit_Call(self, node: libcst.Call) -> None: ...
class ReplaceFileWithContentRule(LintRule):
"""Replace File(path, ...) with Content.from_path(path, ...)."""
METADATA_DEPENDENCIES = (QualifiedNameProvider,)
def visit_Call(self, node: libcst.Call) -> None: ...
Import
# These rules are not imported directly; they are discovered by Fixit via pyproject.toml:
# [tool.fixit]
# enable = [".rules.legacy_methods"]
# For programmatic use or testing:
from rules.legacy_methods import (
ClientCallsRule,
ClientCallRule,
ClientFeedbackRule,
ReplaceFileWithContentRule,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| node | libcst.Call | Yes | A CST Call node visited during tree traversal |
| QualifiedNameProvider metadata | Metadata | For ReplaceFileWithContentRule only | Resolves fully qualified names to match `weave.type_handlers.File.File` |
Outputs
| Name | Type | Description |
|---|---|---|
| Lint violation report | self.report() | Diagnostic message identifying the deprecated API usage |
| Auto-fix replacement | libcst.CSTNode | Modified CST node with the corrected API call |
Usage Examples
Running Fixit Lint
# Check for violations without fixing
fixit lint weave/
# Auto-fix all violations
fixit fix weave/
Deprecated vs. Modern API Calls
# BEFORE (deprecated - flagged by lint rules):
calls = client.calls()
single_call = client.call(call_id)
feedback = client.feedback(call_id)
f = File("data.csv")
# AFTER (modern - no lint violations):
calls = client.get_calls()
single_call = client.get_call(call_id)
feedback = client.get_feedback(call_id)
c = Content.from_path("data.csv")