Class Variable Access and Assignment

Bengt Richter bokr at
Sat Nov 5 02:19:13 CET 2005

On Thu, 03 Nov 2005 13:37:08 -0500, Mike Meyer <mwm at> wrote:
>> I think it even less sane, if the same occurce of b.a refers to two
>> different objects, like in b.a += 2
>That's a wart in +=, nothing less. The fix to that is to remove +=
>from the language, but it's a bit late for that.
Hm, "the" fix? Why wouldn't e.g. treating augassign as shorthand for a source transformation
(i.e., asstgt <op>= expr  becomes by simple text substitution asstgt = asstgt <op> expr)
be as good a fix? Then we could discuss what

    b.a = b.a + 2

should mean ;-)

OTOH, we could discuss how you can confuse yourself with the results of b.a += 2
after defining a class variable "a" as an instance of a class defining __iadd__ ;-)

Or point out that you can define descriptors (or use property to make it easy)
to control what happens, pretty much in as much detail as you can describe requirements ;-)

Bengt Richter

More information about the Python-list mailing list