> On 31 Oct 2020, at 11:27, Steven D'Aprano <st...@pearwood.info> wrote:
>
> 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.
I do not see why you would force the who_cares dict to be created when the
only thing that my use case will do with it is delete it.
I'd like to think that python had the freedom to optimise this construct and
forcing the creating of who_cares seems like it would limit optimisation
choices.
I do not think being the same as sequences is required for dict.
> Barry:
>
>> {'myitem': self.myitem, **other_kwds} = kwds
>
> Indeed.
Barry
_______________________________________________
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/VJUL5DQ23YE25A7MLXKBWZ7FMN5FUE6Z/
Code of Conduct: http://python.org/psf/codeofconduct/