[Python-Dev] Type/class

Guido van Rossum guido@digicool.com
Fri, 11 May 2001 08:31:18 -0500


> > > Good point.  Plain old types currently (in the descr-branch) have a
> > > readonly dict (using a proxy) and no settable attributes.  I will
> > > probably give types settable attributes in a next revision, but I
> > > prefer not to make the type's dict writable -- I need to be able to
> > > watch the setattr calls so that if someone changes
> > > DictType.__getitem__ I can change the mp_subscript to a C function
> > > that calls the __getitem__ method.  

Alas, I think I'll have to withdraw this promise for now.  The truly
built-in types are static objects that are shared between all
interpreter instances within one process, and each type has only one
dictionary pointer.  So changes to the __dict__ would affect other
interpreter instances, and that's unacceptable.

I've thought about alternatives; I can't give each interpreter its own
set of types because sometimes objects are shared between interpreters
(e.g. the dictionary of interned strings), and then then their types
have to be shared too!  Not having any object sharing would mean too
much of a change to the foundations of the implementation.

I think we'll have to live with this restriction until Python 3000.
Personally, I don't mind -- I see mostly possible abuses for the
ability to change attributes of e.g. DictType or StringType. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)