3 ms·
Couldn't they have used "case" and "capture" clauses instead? match status: case not_found: return "Not found" capture success_code:
by coldtea 6y ago
Couldn't they have used "case" and "capture" clauses instead?
match status:
case not_found:
return "Not found"
capture success_code:
return "Returned success code: %s" % success_code
or the "_ as x" or a myriad other ways to make capture explicit...
- ben509 6y agoA 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}"