var or inout parm?

sturlamolden sturlamolden at
Fri Dec 12 16:55:41 CET 2008

On Dec 12, 3:54 pm, Steve Holden <st... at> wrote:
> sturlamolden wrote:
> > On Dec 12, 3:08 pm, Marc 'BlackJack' Rintsch <bj_... at> wrote:
> >> No bug because a mutation *is* attempted.  ``a += x`` calls `a.__iadd__`
> >> which *always* returns the result which is *always* rebound to the name
> >> `a`.  Even with mutable objects where `__iadd__()` simply returns
> >> `self`!
> > No, a mutation is not attempted, even if __iadd__() always returns a
> > value. If a rebinding of a member to the same member is attempted, the
> > tuple should not raise an exception. The tuple should check that it is
> > actually being *mutated* before it raises any exception. There is an
> > attempted write to the tuple, but not an attempted mutation of the
> > tuple. The tuple should tell the difference. Immutability does not
> > imply inwriteability, if the write operation changes nothing. But the
> > tuple raises an exception on any write attempt.
> OK, so if you regard the current behavior as a bug explain how to modify
> the tuple's __iadd__ method and the coding of the INPLACE_ADD operator.
> At least in pseudocode.
> Criticism is easy. Now demonstrate that it's *informed* criticism.
> Enough of the "should". I am always suspicious of suggestions that say
> what the interpreter "should" or "should not" do. It makes it sound as
> though you can wave a magic wand to achieve the desired behavior.

> The interpreter "should not" have a GIL.

> The tuple "should" check that
> it is actually being mutated. How?

In Python it would be something similar to:

def __setitem__(self, index, value):
   if _buf[index] is not value: # given that _buf is the tuple's
internal buffer
      raise TypeError, 'tuple' object does not support item

It should be the tuple's __setitem__ that was invoked here, not
__iadd__, or the parser is faulty.


More information about the Python-list mailing list