Class Variable Access and Assignment
bokr at oz.net
Sat Nov 5 04:33:39 CET 2005
On Fri, 04 Nov 2005 10:28:52 -0500, Christopher Subich <csubich.spam.block at spam.subich.block.com> wrote:
>Antoon Pardon wrote:
>>>Since ints are immutable objects, you shouldn't expect the value of b.a
>>>to be modified in place, and so there is an assignment to b.a, not A.a.
>> You are now talking implementation details. I don't care about whatever
>> explanation you give in terms of implementation details. I don't think
>> it is sane that in a language multiple occurence of something like b.a
>> in the same line can refer to different objects
>This isn't an implementation detail; to leading order, anything that
>impacts the values of objects attached to names is a specification issue.
>An implementation detail is something like when garbage collection
>actually happens; what happens to:
>b.a += 2
>is very much within the language specification. Indeed, the language
>specification dictates that an instance variable b.a is created if one
>didn't exist before; this is true no matter if type(b.a) == int, or if
>b.a is some esoteric mutable object that just happens to define
>__iadd__(self,type(other) == int).
But if it is an esoteric descriptor (or even a simple property, which is
a descriptor), the behaviour will depend on the descriptor, and an instance
variable can be created or not, as desired, along with any side effect you like.
More information about the Python-list