Skip to main content
ai-slop/python-repetitive-dispatchmanual fix

Repetitive string dispatch.

Four or more `if`/`elif x == "..."` branches comparing the same variable against string literals. A dispatch table written out longhand.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

python-repetitive-dispatch.py
✗ Flagged
def handle(event):
    if event.kind == "created":
        on_created(event)
    elif event.kind == "updated":
        on_updated(event)
    elif event.kind == "deleted":
        on_deleted(event)
    elif event.kind == "archived":
        on_archived(event)
Why this trips

Deterministic line match: counts `if`/`elif name == "literal"` branches on the same selector at the same indentation and flags the ladder at four or more.

python-repetitive-dispatch.py
✓ Clean
HANDLERS = {
    "created": on_created,
    "updated": on_updated,
    "deleted": on_deleted,
    "archived": on_archived,
}

def handle(event):
    HANDLERS[event.kind](event)
What changed

Replace the ladder with a dict of handlers or a set membership check, or a `match` statement when the branches genuinely differ in shape.

Each new case in a prompt becomes one more `elif`. Agents extend the ladder rather than introduce a table, so it grows with every feature.

How this rule is justified.

Rule id

ai-slop/python-repetitive-dispatch

Enforcing engine

ai-slop

Detector strategy

Deterministic line match: counts `if`/`elif name == "literal"` branches on the same selector at the same indentation and flags the ladder at four or more.

Legitimate code that is NOT flagged

Ladders of three or fewer, comparisons against non-string values, and branches on different selectors are not flagged.

Evidence

Shipped in aislop v0.9.4 as one of four Python verbosity rules drawn from SlopCodeBench (arXiv 2603.24755).