Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Wandb Weave Op Deco Lint Rule

From Leeroopedia
Knowledge Sources
Domains Code_Quality, Static_Analysis
Last Updated 2026-02-14 10:53 GMT

Overview

Concrete tool for enforcing the preferred `@weave.op` decorator syntax (without empty parentheses), provided by the Fixit lint framework.

Description

The OpDecoRule class extends Fixit's `LintRule` and implements `visit_Decorator` to detect usage of `@weave.op()` with empty parentheses. It matches `libcst.Decorator` nodes where the decorator is a `libcst.Call` whose function is a `libcst.Attribute` on a `libcst.Name` with value `"weave"` and has zero arguments. When matched, it provides an automatic fix that strips the call syntax, replacing the decorator with `@weave.op` (no parentheses). Inline `ValidTestCase` and `InvalidTestCase` declarations serve as built-in test cases for the Fixit framework.

Usage

This lint rule is enabled in pyproject.toml under `[tool.fixit]` as `.rules.op_deco`. It fires automatically during `fixit lint` or `fixit fix` runs. Use this rule to enforce the stylistic convention that `@weave.op` (without empty parentheses) is preferred over `@weave.op()` when no arguments are passed.

Code Reference

Source Location

Signature

class OpDecoRule(LintRule):
    """
    This rule converts @weave.op() to @weave.op.

    This is a stylistic rule that we prefer to use the decorator
    without parentheses.
    """
    VALID = [ValidTestCase("@weave.op")]
    INVALID = [InvalidTestCase("@weave.op()")]

    def visit_Decorator(self, node: libcst.Decorator) -> None:
        """
        Visit Decorator nodes and flag @weave.op() with empty parentheses.
        Provides auto-fix replacement stripping the call syntax.
        """
        ...

Import

# Discovered by Fixit via pyproject.toml:
# [tool.fixit]
# enable = [".rules.op_deco"]

# For programmatic use or testing:
from rules.op_deco import OpDecoRule

I/O Contract

Inputs

Name Type Required Description
node libcst.Decorator Yes A CST Decorator node visited during tree traversal

Outputs

Name Type Description
Lint violation report self.report() Message: "Prefer @weave.op over @weave.op()"
Auto-fix replacement libcst.Decorator Modified Decorator node with call syntax removed

Usage Examples

Running the Lint Rule

# Check for violations
fixit lint weave/ --rules .rules.op_deco

# Auto-fix all violations
fixit fix weave/ --rules .rules.op_deco

Before and After

# BEFORE (flagged by OpDecoRule):
import weave

@weave.op()
def my_function(x: int) -> int:
    return x * 2

# AFTER (auto-fixed):
import weave

@weave.op
def my_function(x: int) -> int:
    return x * 2

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment