[2.2b2]: class variable and classmethod, subclass

Kragen Sitaker kragen at pobox.com
Tue Nov 27 22:31:41 CET 2001


"{-- Rot13 - Hateme" <ungrzr2 at ubatxbat.pbz> writes:
> In 2.2B2
> Inside a class,I did a change to a class variable inside the class'
> classmethod. If the variable has not been changed in the subclass before,
> the class variable in the subclass of the class is also changed. Is this
> behavior intentional or a bug? 

It is intentional, I think, although I didn't write it and so I don't
know; derived classes (subclasses) inherit all attributes from their
base class (superclass) unless they override them (define them
themselves).

> There is no such behavior if the change is done in a normal member
> method.

I assume you mean if you say self.foo = 3 in a normal member method,
dervied classes' foos don't change?  That's because you're setting the
attribute on the instance, not the class.




More information about the Python-list mailing list