Re:Pattern matching accepted for Python
by coldtea on Tuesday February 09, 2021 @09:42PM
(#26085215)
Couldn't they have used "case" and "capture" clauses instead?
or the "_ as x" or a myriad other ways to make capture explicit...
[ Parent
| on HN ]
A separate statement doesn't compose with complex patterns. I'd prefer always requiring the walrus operator to capture:
match response:
case (not_found, msg := _):
return f"Not found: {msg}"
case (error, "No swizzle available"):
return "We lack swizzle. :-("
case pair := (_, "Swizzle"):
log(f"Unexpected swizzle: {pair}")
return f"Swizzle?"
case ((code := _), _):
return f"Success: {code}"