For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /packs/languages/python/conditionals.md.
Quick start

Conditionals

Reject invalid paths first and keep the successful transformation visible.

Branching

Why

Using an exception to distinguish success from failure hides a normal domain alternative from the return type.

Rules

  • MUST use early-return guards for invalid preconditions. [review]
  • MUST handle closed domain alternatives explicitly with structural matching or typed guard branches. [review]
  • MUST avoid authored raise, try/except, and unchecked Result extraction for branching. [review]
  • MUST use Result map for successful pure transforms and bind for fallible transforms. [review]
  • MUST avoid conditional expressions and deeply nested branches around successful paths. [review]
  • MUST configure and verify exhaustiveness checks rather than assume Python match statements are exhaustive. [review]
  • MUST keep assertions for tests rather than runtime input validation. [review]

[review]

Syntax checks can reject exception-control-flow nodes. Strict typing and review establish variant handling; Python alone does not enforce exhaustive matching.

Enforcement

Syntax checks can reject exception-control-flow nodes. Strict typing and review establish variant handling; Python alone does not enforce exhaustive matching.