[2.2b2]: class variable and classmethod, subclass

{-- Rot13 - Hateme ungrzr2 at ubatxbat.pbz
Thu Nov 29 04:58:21 CET 2001


Andreas Kostyrka <andreas at mtg.co.at> wrote in

news:mailman.1006977818.13927.python-list at python.org: 
> #A: a=123(0812828c) []     (08122cd4) B: a=123(0812828c) []    
> (08122cd4) #A: a=123(0812828c) [100]  (08122cd4) B: a=100(08128298)
> [100]  (08122cd4) 
> 
> When you look at A.x, you can see, that it rebind klass.a to a new
> object. (Very important: = just labels a reference in python. It's not
> a classical assignment operator)
> Because of this, when B.x is called, B.a is bound to a different object
> then A.a.
> 
> klass.b OTOH is not rebound, but modified in place. So it A.b and B.b 
> continue to be the same object.
> 

Thanks for the explanation.

The problem is that a new copy of the class variable is only
created if it is changed in the child class. If the variable
is not mutable, that is.

I think it is more natural that the new copies of class variables
are created at the time of subclass definition. Then subclass
and parent class will not share the same class variable references,
whether the variables are mutable or not.



More information about the Python-list mailing list