[Python n00b alert] I'm trying this little script, and I see an exception like: Exception exceptions.AttributeError: "'NoneType' object has no attribute 'refcount'" in <bound method Shape.__del__ of Line> ignored If I change the variable name 's1' to something like 's4', I don't see this exception. Also, if I manually delete the object before the script ends, the exception does not occur. Seems that class Shape is destroyed before all it's objects are destroyed. Is this acceptable?
Logged In: YES user_id=4771 It is not the type object that is cleared, it is the global names of the module. They are replaced with None when the interpreter shuts down, which is why the expression 'Shape.refcount' find None under the name 'Shape'. It's an obscure leftover for historical reasons. I'm not sure why the problem somes bites and sometimes not. A workaround is to avoid reading globals from __del__() methods; e.g. use self.__class__.refcount instead of Shape.refcount... (This of course doesn't excuse the fact that this is a long-standing bug.)