[Python-ideas] PEP: Dict addition and subtraction

Del Gan delgan.py at gmail.com
Mon Mar 4 18:30:06 EST 2019


Hi.

> the augmented assignment version allows anything the ``update`` method allows, such as iterables of key/value pairs

I am a little surprised by this choice.

First, this means that "a += b" would not be equivalent to "a = a +
b". Is there other built-in types which act differently if called with
the operator or augmented assignment version?

Secondly, that would imply I would no longer be able to infer the type
of "a" while reading "a += [('foo', 'bar')]". Is it a list? A dict?

Those two points make me uncomfortable with "+=" strictly behaving
like ".update()".

2019-03-04 17:44 UTC+01:00, Rhodri James <rhodri at kynesim.co.uk>:
> On 04/03/2019 15:12, James Lu wrote:
>>
>>> On Mar 4, 2019, at 10:02 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
>>>
>>> INADA Naoki schrieb am 04.03.19 um 11:15:
>>>> Why statement is not enough?
>>>
>>> I'm not sure I understand why you're asking this, but a statement is
>>> "not
>>> enough" because it's a statement and not an expression. It does not
>>> replace
>>> the convenience of an expression.
>>>
>>> Stefan
>> There is already an expression for key-overriding merge. Why do we need a
>> new one?
>
> Because the existing one is inobvious, hard to discover and ugly.
>
> --
> Rhodri James *-* Kynesim Ltd
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


More information about the Python-ideas mailing list