[Python-ideas] Adding "+" and "+=" operators to dict
Ethan Furman
ethan at stoneleaf.us
Sat Feb 14 21:13:02 CET 2015
On 02/14/2015 11:41 AM, Chris Barker wrote:
> On Sat, Feb 14, 2015 at 11:12 AM, Ethan Furman wrote:
>> On 02/13/2015 06:57 PM, Andrew Barnert wrote:
>> The current design of Python guarantees that an object always gets a setattr
>> or setitem when one of its elements is assigned to. That's an important property,
>> for the reasons I suggested above. So any change would have to preserve that
>> property. And skipping assignment when __iadd__ returns self would not preserve
>> that property. So it's not just backward-incompatible, it's bad.
>
> --> some_var = ([1], 'abc')
> --> tmp = some_var[0]
> --> tmp += [2, 3]
> --> some_var
> ([1, 2, 3], 'abc')
>
> In that example, 'some_var' is modified without its __setitem__ ever being called.
>
> not really -- an object in the some_var is modified -- there could be any number of other references to that object --
> so this is very much how python works.
Oops, I misread what Andrew was saying, sorry!
--
~Ethan~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150214/cd91f8cf/attachment.sig>
More information about the Python-ideas
mailing list