d5DetectabilityOperational debt — how invisible misuse is to your safety net
Closest to 'specialist tool catches' (d5), ruff and pylint can flag isinstance chains or capture-vs-compare mistakes, but subtle issues like name-capture vs literal-match require type checker/lint specialist rules.
e3EffortRemediation debt — work required to fix once spotted
Closest to 'simple parameterised fix' (e3), per quick_fix replacing isinstance/elif chains with match/case is a localized pattern swap within a function or module.
b3BurdenStructural debt — long-term weight of choosing wrong
Closest to 'localised tax' (b3), match/case usage is localized to specific functions handling structured data; it doesn't impose system-wide gravity, though it requires Python 3.10+.
t7TrapCognitive debt — how counter-intuitive correct behaviour is
Closest to 'serious trap' (t7), the misconception that match is a switch statement is catastrophic-adjacent because bare names capture rather than compare — contradicting how switch/case works in every other language a developer knows.
Python 3.10+ structural pattern matching — more powerful than switch/case, matching values, types, sequences, mappings, and class attributes in a single readable construct.
Explanation
Python's match statement is structural pattern matching, not just value comparison. Patterns: literal (case 'GET'), capture (case x), sequence (case [x, y]), mapping (case {'key': value}), class (case Point(x=0, y=y)), OR (case 'GET' | 'POST'), guard (case x if x > 0). The _ wildcard matches anything. Unlike switch/case, it can destructure data — matching a dict's shape and extracting values simultaneously. Particularly powerful for command dispatch, AST processing, and protocol parsing.
Common Misconception
✗ match/case is just Python's switch statement — it is structural pattern matching; it matches shapes, types, and can destructure data, not just compare scalar values.
Why It Matters
Pattern matching replaces deeply nested if/elif chains and isinstance checks with readable, exhaustive pattern matching that the interpreter can reason about.
Common Mistakes
Forgetting that case patterns are not expressions — case 1+1 does not match 2; use case 2.
Mutable capture patterns that shadow outer variables — a bare name in a pattern captures, not compares.
Not using _ as default case — unmatched values silently do nothing without a wildcard case.
Using match where a dict lookup or if/elif is simpler — match shines on structured data, not simple value dispatch.
Code Examples
✗ Vulnerable
# Nested isinstance chain — verbose:
def handle_event(event):
if isinstance(event, dict):
if event.get('type') == 'click':
if 'button' in event:
handle_click(event['button'])
elif event.get('type') == 'key':
handle_key(event.get('key', ''))
✓ Fixed
# Structural pattern matching — readable and exhaustive:
def handle_event(event):
match event:
case {'type': 'click', 'button': button}:
handle_click(button)
case {'type': 'key', 'key': key}:
handle_key(key)
case {'type': 'resize', 'width': w, 'height': h} if w > 0:
handle_resize(w, h)
case _:
log_unknown_event(event)
🧱FUNDAMENTALS— new to this? Start with the ground floor.
PythongeneralPython is a programming language known for readable syntax and versatility, used for web development, data science, automation, and more.
Python's gentle learning curve makes it an ideal first language, while its vast ecosystem keeps it relevant for machine learning, APIs, and DevOps. Skills transfer directly to professional environments because Python runs in production at companies of every size.
💡 When Python throws IndentationError, check that every block uses the same whitespace style—pick spaces (preferably 4) and stick with them everywhere.
Use match for structural pattern matching on complex data — it's more powerful than PHP's match because it can destructure sequences, mappings, and class instances, not just compare values