|
|
|
|
|
by airstrike
1954 days ago
|
|
Yes, and this is incredibly disappointing. Couldn't we achieve the same functionality with a little less ambiguity using the following syntax?: not_found = 404
match status:
case not_found:
return "Not found"
case _ as foo:
do_something(foo)
return "Match anything"
it even works for the example in PEP 365 match json_pet:
case {"type": "cat", "name": _ as name, "pattern": _ as pattern}:
return Cat(name, pattern)
case {"type": "dog", "name": _ as name, "breed": _ as breed}:
return Dog(name, breed)
case _:
raise ValueError("Not a suitable pet")
|
|