python-control-flow
Design or review Python branching, guard clauses, match/case, and truthiness choices.
SKILL.mdskills/python-control-flow/SKILL.md
GitHubPurpose
Choose readable Python control flow without turning every branch into the same style.
Trigger / When to use
Use this skill when:
- code review or design work must choose between
if/elifandmatch/case - a function may benefit from guard clauses or flatter early exits
- a condition may need explicit checks instead of plain truthiness
Do not use this skill when:
- the task is mainly about naming, type-hint syntax, or model selection
- the task is mainly about ternary expressions, walrus, or comprehension style
- the task is mainly about framework or DDD-specific workflow policy
Inputs
- the branch subject or predicate
- whether the subject is closed and owned
- whether
None, empty values, andFalsemean different things - whether cleanup, resource lifetime, or symmetry matters
- any package-specific skill that defines its own exhaustive branching subject
Process
- Choose
match/casefor clear closed dispatch on one subject; keepif/eliffor composite, range-based, unrelated, or guard-heavy branching. - Keep tiny closed splits as
if/elseor explicit checks instead of forcingmatch/case. - Prefer explicit checks when
None, empty values, andFalsediffer; default custom truthy/falsy objects to explicit checks. - Prefer guard clauses for failed preconditions and early exits, but let cleanup symmetry and readability override that preference.
- Put edge notes, anti-patterns,
case _:guidance, and package-specific override examples inexamples.md.
Examples
- Positive: Use
match/casefor anEnumstatus dispatch, use guard clauses for invalid input, and useis Nonewhen0is still a valid value. - Negative: Force
match/casefor a simplebool, rely onif timeout:when0is meaningful, or keep the main path underelseafter a guard already returns.
Outputs
- a review-ready control-flow rule set or skill draft
- a branch-selection matrix with explicit default choices and exceptions
- local examples for common cases and ambiguous edges
Boundaries
- Do not define naming, strict typing syntax, or model-selection policy.
- Do not make pyright the only reason to choose
match/case. - Do not define ternary, walrus, branch-heavy comprehension, or DDD flow rules.
Local references
examples.md: branch examples, edge notes, anti-patterns, and split signals