[Python-ideas] Augmented assignment [was Re: Adding "+" and "+=" operators to dict]

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Feb 15 07:11:25 CET 2015


Andrew Barnert wrote:
> Consider any object with a cache that has to be invalidated when one of its
> members or attributes is set.

If obj were such an object, then obj.member.extend(foo)
would fail to notify it of a change.

Also, if obj1 and obj2 are sharing the same list, then
obj1.member += foo would only notify obj1 of the change
and not obj2.

For these reasons, I wonder whether relying on a side
effect of += to notify an object of changes is a good
design.

-- 
Greg


More information about the Python-ideas mailing list