Class Variable Access and Assignment
Mike Meyer
mwm at mired.org
Fri Nov 4 21:14:17 EST 2005
bokr at oz.net (Bengt Richter) writes:
> On Thu, 03 Nov 2005 13:37:08 -0500, Mike Meyer <mwm at mired.org> 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 ;-)
The problem with += is how it behaves, not how you treat it. But you
can't treat it as a simple text substitution, because that would imply
that asstgt gets evaluated twice, which doesn't happen.
> 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__ ;-)
You may confuse yourself that way, I don't have any problems with it
per se.
> 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 ;-)
I've already pointed that out.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list