prefer-match-none-check
Handle present values before an unconditional None arm in optional-value matches.
Why
A presence check expresses a binary choice directly. For structural dispatch, leading with the concrete cases shows what each value does, and a later None arm handles absence.
Fix
Move the unconditional case None: below the concrete value cases while keeping a final catchall last. When absence exits early or the present arm is pass, use a guard clause such as if (value := lookup()) is None: raise ...; when absence is pass, use if (value := lookup()) is not None:. Otherwise prefer if value is not None: with an else for absence.
Examples
def render(value): match value: case None: return "missing" case str() as text: return text.upper() case _: return "other"def render(value): match value: case str() as text: return text.upper() case None: return "missing" case _: return "other"def render(value): match value: case None: return "missing" case _: return str(value)def render(value): if value is not None: return str(value) return "missing"def label(labels, key): found = labels.get(key) if found is not None: return found.title() return "unknown"def label(labels, key): if (found := labels.get(key)) is not None: return found.title() return "unknown"Autofix output
def label(labels, key): if (found := labels.get(key)) is not None: return found.title() return "unknown"Formerly: prefer-walrus-none-guard