prefer-match-assert-never
Typed enum dispatch must not silently ignore unhandled members.
Why
A wildcard or else branch can hide missing enum members and let newly added members inherit default behavior. Suppressing the argument-type error at assert_never also disables its static exhaustiveness guarantee.
Fix
Handle enum members explicitly and group those that share a default. For an exhausted type, bind the catch-all value and pass it to typing.assert_never; raise an explicit exception when static exhaustiveness is unavailable. Narrow the accepted type or handle missing variants instead of suppressing assert_never's argument check.
Examples
from enum import StrEnum
class Job(StrEnum): CALLER_EXPERIENCE = "caller_experience" JUDGE = "judge" TRANSCRIPT = "transcript" REPORT = "report"
def max_output_tokens(job: Job) -> int: match job: case Job.CALLER_EXPERIENCE: return 4_000 case Job.JUDGE: return 8_000 case _: return 2_000from enum import StrEnumfrom typing import assert_never
class Job(StrEnum): CALLER_EXPERIENCE = "caller_experience" JUDGE = "judge" TRANSCRIPT = "transcript" REPORT = "report"
def max_output_tokens(job: Job) -> int: match job: case Job.CALLER_EXPERIENCE: return 4_000 case Job.JUDGE: return 8_000 case Job.TRANSCRIPT | Job.REPORT: return 2_000 case _ as unreachable: assert_never(unreachable)from enum import StrEnum
class Kind(StrEnum): A = "a" B = "b" C = "c"
def handle(kind: Kind) -> None: match kind: case Kind.A: handle_a() case Kind.B: handle_b() case _: passfrom enum import StrEnumfrom typing import assert_never
class Kind(StrEnum): A = "a" B = "b" C = "c"
def handle(kind: Kind) -> None: match kind: case Kind.A: handle_a() case Kind.B: handle_b() case Kind.C: handle_c() case _ as unreachable: assert_never(unreachable)