Message26430
Logged In: YES
user_id=56214
This is not a bug. The language-defined behavior of
augmented assignment is that:
lvalue |= rvalue
translates to:
lvalue = lvalue.__ior__(rvalue)
Since in this example the lvalue cannot be assigned to, it
is your code that has the bug. Note that some objects'
__ior__ method may not return the same object! Therefore,
using a tuple to store the target of an in-place update
would only work with objects whose __ior__ returns self. If
you know that this will always be the case in your code,
then simply do this:
ts = t[0]
ts |= set([7])
Again, note that this means that if t[0].__ior__ does not
return self, then ts will not be the same object as t[0],
leaving the tuple un-updated. In short, you can't use
augmented assignments to tuple items in the general case.
Note, by the way, that sets have other methods for in-place
updating, and your code would probably be clearer using one
of those, since no lvalue confusion arises. The whole
purpose of augmented assignment is to deal with the
possibility that an in-place update might or might not
result in the same object. If an object offers a method that
unequivocally mutates it, your code will be clearer using that.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:34:54 | admin | link | issue1306777 messages |
2007-08-23 14:34:54 | admin | create | |
|