On Sat, Oct 31, 2020 at 08:24:04AM +0000, Barry Scott wrote: > > On 31 Oct 2020, at 06:35, Steven D'Aprano <st...@pearwood.info> wrote: > > > > I think we can promise that: > > > > * if the mapping on the right has missing keys, no assignments occur; > > > > * if the mapping on the right has extra keys, and there is no double > > star target to capture the extras, then no assignments occur; > > Why must I always handle all keys in the dictionary?
You don't. Use a double-star target to capture the excess, then ignore it. This is similar to sequence unpacking: spam, eggs, *who_cares = sequence {'spam': spam, 'eggs', eggs, **who_cares} = mapping will collect any excess items into `who_cares`. In the first case, it will be a list; in the second, it will be a dict. Barry: > {'myitem': self.myitem, **other_kwds} = kwds Indeed. -- Steve _______________________________________________ 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/HDJHDKE24PE4QP3UWZSVGEA56J4AWWZZ/ Code of Conduct: http://python.org/psf/codeofconduct/