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.

Principle:Wandb Weave Decorator Style Enforcement

From Leeroopedia
Revision as of 17:53, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Wandb_Weave_Decorator_Style_Enforcement.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Code_Quality, Static_Analysis
Last Updated 2026-02-14 10:53 GMT

Overview

Principle of enforcing consistent decorator syntax across a codebase via CST-based static analysis and auto-fix.

Description

Decorator Style Enforcement addresses visual inconsistency when a decorator accepts optional arguments. In Python, `@decorator` and `@decorator()` are functionally equivalent when no arguments are passed, but mixing the two forms creates inconsistent style. This principle uses a lint rule to detect the verbose form (with empty parentheses) and automatically rewrites it to the concise form (without parentheses). In Weave's case, this ensures `@weave.op` is always used instead of `@weave.op()`, reducing visual noise and maintaining a uniform coding style.

Usage

Apply this principle when a project has decorators that support both called (`@deco()`) and uncalled (`@deco`) forms and wants to enforce a single canonical style. This is particularly useful for decorator-heavy APIs like Weave's `@weave.op`.

Theoretical Basis

The mechanism uses a CST Decorator visitor:

  1. Visit: Each `Decorator` node in the syntax tree is visited.
  2. Match: The visitor checks if the decorator is a `Call` node with zero arguments whose function matches the target pattern (e.g., `weave.op`).
  3. Simplify: If matched, the `Call` wrapper is stripped, leaving only the attribute reference as the decorator.

Pseudo-code Logic:

# Abstract algorithm (NOT real implementation)
for decorator_node in cst.walk(source_tree):
    if is_call_with_no_args(decorator_node) and matches_target(decorator_node):
        simplified = strip_call_syntax(decorator_node)
        report(decorator_node, message, simplified)

Related Pages

Page Connections

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