from typing import Literal, assert_never
Status = Literal["draft", "published", "archived"]
def describe(status: Status) -> str:
match status:
case "draft": return "Not yet visible"
case "published": return "Live to readers"
case "archived": return "Hidden but preserved"
case _: assert_never(status) # mypy enforces this
print(describe("draft")) # Not yet visible
# describe("deleted") # mypy error: not a Status literal
Create a free account and build your private vault. Share publicly whenever you want.