Skip to content

prefer-or-pattern

Merge adjacent case arms with identical bodies into one or-pattern.

Why

An or-pattern expresses shared handling once and prevents identical arms from drifting apart.

Fix

Join the equivalent patterns with | and keep their shared body under the merged arm.

Examples

Before — flagged Adjacent match arms repeat one body
app/settings.py
def status(value):
match value:
case "queued":
return "active"
case "running":
return "active"
After — preferred One or-pattern owns the shared body
app/settings.py
def status(value):
match value:
case "queued" | "running":
return "active"