On Thu, Feb 3, 2022 at 11:53 AM Yurii Karabas <1998uri...@gmail.com> wrote:
> > Proposed syntax: > > m = {"a": 1, "b": 2, "c": 3, "d": 4} > > {a, b} = m # a: 1, b: 2 > {a, b, **rest} = m # a: 1, b: 2, rest: {c: 3, d: 4} > > as equivalent to this from PEP 634: > match m: > case {"a": a, "b": b, **rest}: > pass > case _: > raise ValueError What I find particularly unsatisfying is that the left hand side syntax in your proposal {a, b, **rest} is not at all like, the case syntax {"a": a, "b": b, **rest} so that's twice as much syntax to learn. *IF* this is really used often enough that it is worth adding to the language it should be a variation of match, something like: match m as {"a": a, "b": b, **rest} The match clause defaults to doing nothing if the value doesn't match but that's less useful here (and harder to deal with since figuring out that a, b, and rest are still unbound is clumsy, so I would agree that it should raise ValueError if there's no match. --- Bruce
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ZQZAJLBX2FJENEN6XKSWCI3Q6QTHTHAS/ Code of Conduct: http://python.org/psf/codeofconduct/