2 ms·
Technically I think this feature would do unpacking for you, just more verbosely, like so: d = {"a": 1, "b": 2, "c": 3, "z": 4} match d: case {"a": a,
by iamevn 6y ago
Technically I think this feature would do unpacking for you, just more verbosely, like so:
d = {"a": 1, "b": 2, "c": 3, "z": 4}
match d:
case {"a": a, "b": b, "z": z}:
print(a, b, z)
o = SomeObject(someval=42)
match o:
case SomeObject(someval=someval):
print(someval)
from https://www.python.org/dev/peps/pep-0636/#going-to-the-cloud-mappings https://www.python.org/dev/peps/pep-0636/#going-to-the-cloud... and https://www.python.org/dev/peps/pep-0636/#adding-a-ui-matching-objects https://www.python.org/dev/peps/pep-0636/#adding-a-ui-matchi...
it's more verbose but lets you easily add a default case to catch and handle when a key you expected to be in the dict isn't or the object doesn't actually match the object you expect.